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

Fix/calllist typing #690

Merged
merged 5 commits into from
Nov 6, 2023
Merged

Conversation

howamith
Copy link
Contributor

@howamith howamith commented Nov 5, 2023

Typing for the CallList class was improved in 0.23.0 (see #593), however this has regressed in 0.24.0 - I believe through the changes made in #684. This PR reintroduces the improved typing from #593.

I've tried to add a test to ensure this doesn't happen again, however it's currently evergreen as mypy isn't run on the tests. (IMHO mypy - and any other static analysis tools - should be run against the tests. Type hints are great and their use should be encouraged, however by not checking the tests there's nothing checking how these types work from the perspective of the code consuming this package - which is probably how this was missed in #684.)

I did have a brief go at running mypy over the tests to give the new test a bit more purpose (and to improve coverage generally), but there were 754 errors so that feels like something that should be addressed in its own PR.

@howamith howamith marked this pull request as ready for review November 5, 2023 22:35
setup.py Outdated Show resolved Hide resolved
@@ -241,6 +246,14 @@ def __iter__(self) -> Iterator[Call]:
def __len__(self) -> int:
return len(self._calls)

@overload
def __getitem__(self, idx: int) -> Call:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Recent version of mypy doesn't require overload, why do we necessarily need it?

Choose a reason for hiding this comment

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

I have mypy==1.6.1, which is the most current version and it still throws:

error: Item "list[Call]" of "Call | list[Call]" has no attribute "request"  [union-attr]

Changes in this PR should fix that. I can't really imagine how would mypy guess the appropriate combination of input and output types without overload.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous CI passed just fine with mypy, although I saw some flakiness in results in the last couple of months

What is the difference then?

Copy link
Contributor Author

@howamith howamith Nov 6, 2023

Choose a reason for hiding this comment

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

CI will still pass because mypy isn't being run against the tests. The definition of CallList's __getitem__ method is fine. It's where it's used that becomes a problem. You can reproduce this locally by removing the line that excludes the tests from mypy in the .ini file.

This is why I've suggested running static analysis on the tests.

Copy link
Collaborator

@beliaev-maksim beliaev-maksim Nov 6, 2023

Choose a reason for hiding this comment

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

then we indeed need to enabling mypy on tests to validate this PR and all the future PRs

Copy link
Contributor Author

@howamith howamith Nov 6, 2023

Choose a reason for hiding this comment

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

Is it worth getting this out to fix the regression, and then dealing with enabling static analysis in the tests in a separate PR? My original intention was to do that here but after removing the exclusion from the mypy config file there were 754 errors. Fixing those is going to make the diff really noisy and feels like a separate issue (IMO).

Happy to address here if that's preferred!

@markstory markstory merged commit c46cb06 into getsentry:master Nov 6, 2023
12 checks passed
@howamith howamith deleted the fix/calllist-typing branch November 7, 2023 10:18
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.

None yet

4 participants