Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Fix incompatible overrides of overloaded methods in concrete subclasses#14017
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
5c90d1ed62b1c78e575a560a5d9f992e2527606d50635e575File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Fixes#14002
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1868,6 +1868,19 @@ def check_method_override_for_base_with_name( | ||
| original_class_or_static = False # a variable can't be class or static | ||
| if isinstance(original_type, FunctionLike): | ||
| active_self_type = self.scope.active_self_type() | ||
| if isinstance(original_type, Overloaded) and active_self_type: | ||
| # If we have an overload, filter to overloads that match the self type. | ||
| # This avoids false positives for concrete subclasses of generic classes, | ||
| # see testSelfTypeOverrideCompatibility for an example. | ||
| # It's possible we might want to do this as part of bind_and_map_method | ||
| filtered_items = [ | ||
| item | ||
| for item in original_type.items | ||
| if not item.arg_types or is_subtype(active_self_type, item.arg_types[0]) | ||
| ] | ||
| if filtered_items: | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. If there are no filtered_items, shouldn't we always treat the override as compatible? e.g. in your CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yeah, I wasn't sure about this, but it seemed like a weird situation so I chose to fail. Feels sketchy to introduce a | ||
| original_type = Overloaded(filtered_items) | ||
| original_type = self.bind_and_map_method(base_attr, original_type, defn.info, base) | ||
| if original_node and is_property(original_node): | ||
| original_type = get_property_type(original_type) | ||