-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Handle possibly-unbound instance members #16363
Conversation
# Emitting a diagnostic in a case like this is not something we support, and it's unclear | ||
# if we ever will (or want to) |
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.
We came to the same conclusion in an earlier PR. This is also mentioned higher up in this test suite. And mypy/pyright don't emit a diagnostic for this either (which is also mentioned higher up). This test is only added here for easier reference / completeness.
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.
Looks good! A couple of minor questions
The handling of inherited attributes here reminds me that we will also need to add eager Liskov checking for inherited classes (once we have callable types and can do callable subtype checks). For a mutable attribute (which all are by default) a strict Liskov interpretation would require invariance, which would make the union handling here irrelevant. |
Mainly curious: is this true even in the presence of gradual types? Could a subclass refine a base-class |
That's a good point: I think that would make sense. |
ad83ea5
to
8916f25
Compare
class.own_instance_member(db, name) | ||
{ | ||
return member; | ||
// TODO: We could raise a diagnostic here if there are conflicting type qualifiers |
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.
Probably the diagnostic would be raised by an eager Liskov check at the inheritance site, rather than here? But it doesn't hurt to have a TODO here until we do that.
Summary
Adds support for possibly-unbound/undeclared instance members.
Test Plan
New MD tests.