Skip to content

Commit 36f70ef

Browse files
Refactor path_type_label
1 parent 93d7b7b commit 36f70ef

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pydantic_settings/utils.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
from collections.abc import Callable
12
from pathlib import Path
23

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',
4+
_PATH_TYPE_LABELS: dict[Callable[[Path], bool]] = {
5+
Path.is_dir: 'directory',
6+
Path.is_file: 'file',
7+
Path.is_mount: 'mount point',
8+
Path.is_symlink: 'symlink',
9+
Path.is_block_device: 'block device',
10+
Path.is_char_device: 'char device',
11+
Path.is_fifo: 'FIFO',
12+
Path.is_socket: 'socket',
1213
}
1314

1415

@@ -17,8 +18,8 @@ def path_type_label(p: Path) -> str:
1718
Find out what sort of thing a path is.
1819
"""
1920
assert p.exists(), 'path does not exist'
20-
for method, name in path_type_labels.items():
21-
if getattr(p, method)():
21+
for method, name in _PATH_TYPE_LABELS.items():
22+
if method(p):
2223
return name
2324

2425
return 'unknown'

0 commit comments

Comments
 (0)