vulture
vulture copied to clipboard
Add support for TypedDict
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
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.
I don't see an easy way to remove the false positive. Suggestions welcome :-)
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. 🙂
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
...
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