PathLike Typing Library / Библиотека PathLike Typing
English Documentation
Overview
pathlike-typing is a lightweight Python library that provides a standardized type alias PathLike for representing file system paths in type annotations. It simplifies working with path objects by unifying Path (from pathlib) and str types under a single type hint.
Installing
pip install pathlike-typing
Version
Current version: 1.0.0
Usage
from pathlib import Path
from pathlike_typing import PathLike
# Use PathLike in type annotations
def read_file(path: PathLike) -> str:
# Both Path objects and strings are accepted
with open(path, 'r') as f:
return f.read()
# Both will work:
read_file(Path("/home/user/file.txt"))
read_file("/home/user/file.txt")
Type Alias
The library provides one main export:
PathLike: Type alias forUnion[Path, str]
Exports
__all__ = ["PathLike", "__version__"]
Why Use This Library?
- Consistency: Standardizes path type annotations across your codebase
- Clarity: Makes function signatures clearer about what types of path arguments are accepted
- Compatibility: Works seamlessly with both pathlib.Path objects and traditional string paths
- Lightweight: Minimal dependencies and overhead
License
MIT License - See LICENSE file for details.
Документация на русском языке
Обзор
pathlike-typing — это облегчённая библиотека Python, предоставляющая стандартизированный псевдоним типа PathLike для представления путей к файловой системе в аннотациях типов. Она упрощает работу с объектами путей, объединяя типы Path (из pathlib) и str под единым указанием типа.
Установка
pip install pathlike-typing
Версия
Текущая версия: 1.0.0
Использование
from pathlib import Path
from pathlike_typing import PathLike
# Используйте PathLike в аннотациях типов
def read_file(path: PathLike) -> str:
# Поддерживаются как объекты Path, так и строки
with open(path, 'r') as f:
return f.read()
# Поддерживаются оба варианта:
read_file(Path("/home/user/file.txt"))
read_file("/home/user/file.txt")
Псевдоним типа
Библиотека предоставляет один основной экспорт:
PathLike: Псевдоним типа дляUnion[Path, str]
Экспорт
__all__ = ["PathLike", "__version__"]
Зачем использовать эту библиотеку?
- Единообразие: Стандартизирует аннотации типов путей в вашей кодовой базе.
- Ясность: Делает сигнатуры функций более понятными для определения типов принимаемых аргументов путей.
- Совместимость: Без проблем работает как с объектами pathlib.Path, так и с традиционными строковыми путями.
- Легковесность: Минимальные зависимости и накладные расходы.
Лицензия
Лицензия MIT — подробности см. в файле LICENSE.
Metadata
Release files for pathlike-typing 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pathlike_typing-1.0.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pathlike_typing-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / pathlike_typing-1.0.0.tar.gz
| Download URL | pathlike_typing-1.0.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7adc47fc4565cde49053c8bcd1e08a06dfb46e1a0789ed94c15ce9b663e4bb96
|
|
BLAKE2b-256 checksum How to use checksums |
922cb3f00636edf4d4b727e5f34e49ba3f4154588a360bffcce5fb046e532963
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / pathlike_typing-1.0.0-py3-none-any.whl
| Download URL | pathlike_typing-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed656aadf7ea7b8f2145fc37f00cdff1ddf666f676b7306a173a8cdef701b449
|
|
BLAKE2b-256 checksum How to use checksums |
56da9c97ed4ccf2ceabeed509750df0557446603a130ff6923aa899c232fdfad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|