Uh oh!
There was an error while loading. Please reload this page.
Don't flag intentionally empty generators unreachable - #15722
Conversation
ikonst
commented
Jul 20, 2023
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
| yield None | ||
| self.inferred_attribute_types = old_types | ||
| def _is_empty_generator(self, func: FuncItem) -> bool: |
There was a problem hiding this comment.
| def_is_empty_generator(self, func: FuncItem) ->bool: | |
| @staticmethod | |
| def_is_empty_generator(func: FuncItem) ->bool: |
Or even better: move the function into the global scope?
| # | ||
| # TODO: Find a way of working around this limitation | ||
| if len(expanded) >= 2: | ||
| if len(expanded) >= 2 or self._is_empty_generator(item): |
There was a problem hiding this comment.
Maybe update the multiline comment immediately above this line? We're not just suppressing reachability warnings for TypeVars with value restrictions anymore
There was a problem hiding this comment.
Yeah, I didn't want to muddy the blame for that comment 🤣
e31efd3 to
5e33f47Compare| return ( | ||
| len(body := func.body.body) == 2 |
There was a problem hiding this comment.
Nit: I think the first walrus here is slightly gratuitous
| return ( | |
| len(body:=func.body.body) ==2 | |
| body=func.body.body | |
| return ( | |
| len(body) ==2 |
| # We suppress reachability warnings for empty generators (return; yield), since there's | ||
| # no way to promote a function into a generator except by adding an "unreachable" yield. |
There was a problem hiding this comment.
| # We suppress reachability warnings for empty generators (return; yield), since there's | |
| # no way to promote a function into a generator except by adding an "unreachable" yield. | |
| # We also suppress reachability warnings for empty generator functions | |
| # (return; yield), since the most idiomatic way to promote a function into a | |
| # generator function is often to add an "unreachable" yield. |
There was a problem hiding this comment.
I had "also" at first, but I wanted to be able to remove the first comment w/o touching the second.
There was a problem hiding this comment.
Meh, I think I'd personally prioritise a readable comment over a tiny bit more churn in git blame :p
There was a problem hiding this comment.
Ahh, easy. I've just made the "TODO remove me" part second. :P
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This comment has been minimized.
This comment has been minimized.
@AlexWaygood I removed the comment in a090d56 since now this field appears to have a long-term legitimate use. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core): typechecking got 1.05x slower (366.9s -> 386.6s)
(Performance measurements are based on a single noisy sample)
|
Fixes#15345.