Skip to content

Commit a37d07c

Browse files
Refactor path_type_label (#458)
1 parent 93d7b7b commit a37d07c

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pydantic_settings/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from pathlib import Path
22

3-
path_type_labels = {
4-
'is_dir': 'directory',
5-
'is_file': 'file',
6-
'is_mount': 'mount point',
7-
'is_symlink': 'symlink',
8-
'is_block_device': 'block device',
9-
'is_char_device': 'char device',
10-
'is_fifo': 'FIFO',
11-
'is_socket': 'socket',
3+
_PATH_TYPE_LABELS = {
4+
Path.is_dir: 'directory',
5+
Path.is_file: 'file',
6+
Path.is_mount: 'mount point',
7+
Path.is_symlink: 'symlink',
8+
Path.is_block_device: 'block device',
9+
Path.is_char_device: 'char device',
10+
Path.is_fifo: 'FIFO',
11+
Path.is_socket: 'socket',
1212
}
1313

1414

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

2424
return 'unknown'

tests/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pydantic_settings.utils import path_type_label
2+
3+
4+
def test_path_type_label(tmp_path):
5+
result = path_type_label(tmp_path)
6+
assert result == 'directory'

0 commit comments

Comments
 (0)