beetbox/confuse

Typing support

henryiii opened this issue · 2 comments

Would it be possible to add type hints/type comments/type stubs (one of those) to support MyPy, PyCharm, etc?

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).

We'd certainly be happy to add it! Pul requests would be welcome. For the time being, however, it will need to stay in a stub for Python 2 compatibility… hopefully beets as a whole will drop that soon and we'll be able to go Python 3-only.