Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Loading