Mark code after for loops that never end as unreachable#19287
Mark code after for loops that never end as unreachable#19287A5rocks wants to merge 8 commits intopython:masterfrom
Conversation
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
|
Looks good! However, I'm afraid that This (untested, sorry for any typos) should print "Reached", and this PR should mark that line unreachable. It's a separate problem, of course, but I'm not sure this can be merged until we can somehow enforce |
|
I'm not sure it's possible to enforce any distinction there. We could enforce that |
|
I'll think about this tomorrow. The problem stems from the fact that |
|
Sorry yes that's what I meant re: I'm not convinced that subclassing a subclass will work correctly for |
This comment has been minimized.
This comment has been minimized.
|
Hm, okay, I revisited this once again, maybe it's not really a blocker and we should file a separate feature request to check third type argument of I don't think we need to support initial definition in subclasses. This should be an error even if some subclasses define class G(Generator[int, None, str]):
def __iter__(self) -> 'G':
return self
def __next__(self) -> int:
raise StopIteration
def send(self, value: None, /) -> int:
assert False, "unused"
def throw(
self, typ: object, val: object = None, tb: object | None = None, /
) -> int:
assert False, "unused"On the other hand, if the direct subclass of I only envision this as a sanity check specifically for |
|
@sterliakov sorry I haven't actually thought about this more until now. I think pushing off doing this properly is fine. I think doing this properly could be what you talk about, or it could be something like:
EDIT: nevermind, I thought a bit more and the second approach wouldn't work (because we need to say there's a |
|
Fixes #7374? |
|
Good catch, I'll separate out the part of that issue that this doesn't fix into another issue. |
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Fixes #18891
Fixes #7374