jendrikseipp / vulture

Find dead Python code
MIT License
3.48k stars 152 forks source link

Add type hints for the `get_unused_code` function and the fields of `Item`. #361

Closed johndoknjas closed 2 weeks ago

johndoknjas commented 3 months ago

Description

This PR adds type hints to make it slightly easier for users to use the api. Now for each element from get_unused_code, IDEs will display their type as Item when highlighting over the variable. The same is done for the fields of Item, such as making filename's type a Path (removing any potential confusion about whether it's a string).

Related Issue

Checklist:

jendrikseipp commented 3 months ago

Thanks for the PR! I'm a bit reluctant to merge it because type annotations without tests might get outdated quickly when the code changes. Is there a way to test that all type annotations are correct, while ignoring all other typing issues that a tool like Mypy might detect? Could you add such a test?

johndoknjas commented 3 months ago

@jendrikseipp For sure, I'll work on adding a test to do this.

johndoknjas commented 3 months ago

@jendrikseipp I've added a test that runs mypy, disabling error codes that mypy complains about at the moment. All of them seem like codes that in general shouldn't be needed to detect wrong type annotations.

By the way, before disabling the attr-defined error code, I noticed mypy called out lines 552 and 659 in core.py - not sure if it's right about these being issues.

jendrikseipp commented 3 months ago

Thanks, I'll have a closer look at this when time allows.

johndoknjas commented 3 weeks ago

Hey @jendrikseipp, just following up on this PR.

jendrikseipp commented 2 weeks ago

Thanks for your work on this!

johndoknjas commented 2 weeks ago

No problem, and thank you for your feedback :)