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

Add Type Annotations #116

Closed
hawkins opened this issue May 9, 2019 · 7 comments
Closed

Add Type Annotations #116

hawkins opened this issue May 9, 2019 · 7 comments

Comments

@hawkins
Copy link

hawkins commented May 9, 2019

It would be stellar if Addict had type annotations (maybe in a .pyi file next to addict.py?) such that we could use this in projects using pyre, mypy, pyright, pytype etc.

I imagine this would be pretty simple to make since the functions so closely resemble a Dict's in the first place, but I don't know the best way to distribute these types (typeshed? .pyi?).

If this is something you're open to, I can write the types later and PR them or look more into how best to distribute them

@mewwts
Copy link
Owner

mewwts commented May 9, 2019

That would be very cool @hawkins.

I'm not too familiar with the typing landscape at the moment, but it seems like .pyi / typeshed are the way to go.

If this is something you're willing to research, I'm open to adding it!

@hawkins
Copy link
Author

hawkins commented May 9, 2019

Awesome, thanks! I'll circle back later this weekend once I know a little more about how this could best work.

@mewwts
Copy link
Owner

mewwts commented Mar 15, 2020

@hawkins are you still keen on creating this?

@hawkins
Copy link
Author

hawkins commented Mar 17, 2020

Sorry! I was never clear on the best way to distribute types, but I think you can add a .pyi next to your source code and then update setup.py to include them.

Here's what we use locally now, just from stubgen -p addict. It's not complete, but it's a start for anyone like me who wants something quick and easy.

# Stubs for addict.addict (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any, Optional

class Dict(dict):
    def __init__(__self: Any, *args: Any, **kwargs: Any) -> None: ...
    def __setattr__(self, name: Any, value: Any) -> None: ...
    def __setitem__(self, name: Any, value: Any) -> None: ...
    def __add__(self, other: Any): ...
    def __getattr__(self, item: Any): ...
    def __missing__(self, name: Any): ...
    def __delattr__(self, name: Any) -> None: ...
    def to_dict(self): ...
    def copy(self): ...
    def deepcopy(self): ...
    def __deepcopy__(self, memo: Any): ...
    def update(self, *args: Any, **kwargs: Any) -> None: ...
    def __getnewargs__(self): ...
    def setdefault(self, key: Any, default: Optional[Any] = ...): ...

There's obviously room to improve, i.e., to_dict(self: Dict) -> typing.Dict[Any, Any]: .... For those that overwrite dict methods, I don't know if their function signatures need to be typed since dict's is, i.e., __setitem__.

Here's the bad news though, I'm not using this project in any active development I have anymore, so I can try to find the time, but we both see how that went last year when I was using it 😕 Sorry! I miss writing Python though, so we'll see if I can find the time with a potential quarantine upcoming. (🤞)

@mewwts
Copy link
Owner

mewwts commented Mar 18, 2020

Got it.

I'm not actively using Python much these days either, so I'll close this until someone else needs/wants it.

Thanks for using addict!

@mewwts mewwts closed this as completed Mar 18, 2020
@stdedos
Copy link

stdedos commented Sep 23, 2022

Does up-voting on the top post counts until someone else wants it?

I'd take the stubgen version anytime and accumulatively improve it, rather than have no typing at all 😕

(Also, would you mind closing this as incomplete? 😄)

@stdedos
Copy link

stdedos commented Sep 23, 2022

Also, duplicate #147

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

3 participants