Skip to content

Conversation

@johndoknjas
Copy link
Contributor

@johndoknjas johndoknjas commented Jul 22, 2024

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:

  • I have updated the documentation in the README.md file or my changes don't require an update.
  • I have added an entry in CHANGELOG.md.
  • I have added or adapted tests to cover my changes.
  • I have run pre-commit run --all-files to format and lint my code.

@jendrikseipp
Copy link
Owner

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
Copy link
Contributor Author

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

@johndoknjas
Copy link
Contributor Author

@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
Copy link
Owner

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

@johndoknjas
Copy link
Contributor Author

Hey @jendrikseipp, just following up on this PR.

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your persistence :)



@pytest.mark.skipif(
sys.version_info >= (3, 13), reason="Need python < 3.13 for pytype"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sys.version_info >= (3, 13), reason="Need python < 3.13 for pytype"
sys.version_info >= (3, 13), reason="needs Python < 3.13 for pytype"

@jendrikseipp jendrikseipp merged commit 798809a into jendrikseipp:main Oct 9, 2024
19 checks passed
@jendrikseipp
Copy link
Owner

Thanks for your work on this!

@johndoknjas
Copy link
Contributor Author

No problem, and thank you for your feedback :)

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

Successfully merging this pull request may close these issues.

3 participants