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 support for TypedDict #249

Closed
ZeeD opened this issue Feb 12, 2021 · 5 comments
Closed

Add support for TypedDict #249

ZeeD opened this issue Feb 12, 2021 · 5 comments

Comments

@ZeeD
Copy link

ZeeD commented Feb 12, 2021

snippet:

from typing import TypedDict

class C(TypedDict):
    key: int

c: C = {'key': 0}
print(c['key'])

vulture says unused variable 'key' (60% confidence), but shouldn't

@RJ722
Copy link
Contributor

RJ722 commented Mar 11, 2021

I agree that this should be done, but I'm not sure how complicated would it be. I'll take a look into it. A lot of things on my plate right now, so it will take some time.

@jendrikseipp
Copy link
Owner

I don't see an easy way to remove the false positive. Suggestions welcome :-)

@mariuswallraff
Copy link

No suggestion, but for other people landing here:
A workaround is to use the function-call syntax like this:
C = TypedDict("C", {"key": int})

You can't use the nicer-looking keyword syntax, because then mypy is going to complain again. 🙂

@janosh
Copy link

janosh commented Sep 4, 2022

You can also noqa all the attributes though like the readme says, it ain't pretty:

class ProcessResponse(TypedDict):
    timer: str  # noqa: F841
    status: str  # noqa: F841
    download_filename: str  # noqa: F841
    filesize: int  # noqa: F841
    ...

@jendrikseipp
Copy link
Owner

jendrikseipp commented Jan 8, 2023

Thanks for the suggestions! I'd use a whitelist module for this. I don't see a way to bake support for this into Vulture.

Example whitelist module:

from myfile import C
C.key

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

5 participants