Skip to content

Commit

Permalink
Refactor path_type_label
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenda-optifino committed Oct 25, 2024
1 parent 93d7b7b commit 36f70ef
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pydantic_settings/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from collections.abc import Callable
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: dict[Callable[[Path], bool]] = {
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 +18,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'

0 comments on commit 36f70ef

Please sign in to comment.