Typing support
henryiii opened this issue · 2 comments
henryiii commented
Would it be possible to add type hints/type comments/type stubs (one of those) to support MyPy, PyCharm, etc?
henryiii commented
If it helps, here's the stub I'm currently using (and has already caught a bug in my code as I'm adopting confuse!):
confuse.pyi
from typing import TypeVar, Type, overload, AnyStr, Union
from os import PathLike
T = TypeVar("T")
Path = Union[AnyStr, PathLike[AnyStr]]
class ConfigView:
def __getitem__(self, item: str) -> "ConfigView": ...
@overload
def get(self) -> str: ...
@overload
def get(self, template: Type[T]) -> T: ...
class Configuration:
def __init__(self, appname: str, modname: str = None, read: bool = True): ...
def set_file(self, filename: Path) -> None: ...
def clear(self) -> None: ...
def __getitem__(self, item: str) -> ConfigView: ...
The tutorial here https://realpython.com/python-type-checking/ is helpful. This is very minimal, only covering the parts I'm currently using, and leaving out the details of the possible inputs to get (which are not just types).