Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing support #81

Open
henryiii opened this issue Apr 23, 2020 · 2 comments
Open

Typing support #81

henryiii opened this issue Apr 23, 2020 · 2 comments

Comments

@henryiii
Copy link

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

@henryiii
Copy link
Author

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

@sampsyo
Copy link
Member

sampsyo commented Apr 24, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants