-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Mark code after for loops that never end as unreachable #19287
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
base: master
Are you sure you want to change the base?
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 |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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 |
B = TypeVar("B") | ||
C = TypeVar("C") | ||
|
||
class GeneratorSubtype(Generator[A, B, C]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also test this with specific subtype like class MyGenerator(Generator[int, None, NoReturn])
? And maybe a perverse case of class ShuffledGenerator(Generic[A, B, C], Generator[C, B, A])
@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. |
Fixes #18891
Fixes #7374