Skip to content

Commit

Permalink
Refactor path_type_label (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenda-optifino authored Oct 31, 2024
1 parent 93d7b7b commit a37d07c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pydantic_settings/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pathlib import Path

path_type_labels = {
'is_dir': 'directory',
'is_file': 'file',
'is_mount': 'mount point',
'is_symlink': 'symlink',
'is_block_device': 'block device',
'is_char_device': 'char device',
'is_fifo': 'FIFO',
'is_socket': 'socket',
_PATH_TYPE_LABELS = {
Path.is_dir: 'directory',
Path.is_file: 'file',
Path.is_mount: 'mount point',
Path.is_symlink: 'symlink',
Path.is_block_device: 'block device',
Path.is_char_device: 'char device',
Path.is_fifo: 'FIFO',
Path.is_socket: 'socket',
}


Expand All @@ -17,8 +17,8 @@ def path_type_label(p: Path) -> str:
Find out what sort of thing a path is.
"""
assert p.exists(), 'path does not exist'
for method, name in path_type_labels.items():
if getattr(p, method)():
for method, name in _PATH_TYPE_LABELS.items():
if method(p):
return name

return 'unknown'
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic_settings.utils import path_type_label


def test_path_type_label(tmp_path):
result = path_type_label(tmp_path)
assert result == 'directory'

0 comments on commit a37d07c

Please sign in to comment.