-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Stubtest: check _value_ for ellipsis-valued stub enum members
#19760
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
Changes from all commits
3471156
ce659ac
d30f5f6
0e58ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1274,6 +1274,7 @@ def verify_var( | |
| yield Error(object_path, "is read-only at runtime but not in the stub", stub, runtime) | ||
|
|
||
| runtime_type = get_mypy_type_of_runtime_value(runtime, type_context=stub.type) | ||
| note = "" | ||
| if ( | ||
| runtime_type is not None | ||
| and stub.type is not None | ||
|
|
@@ -1286,17 +1287,28 @@ def verify_var( | |
| runtime_type = get_mypy_type_of_runtime_value(runtime.value) | ||
| if runtime_type is not None and is_subtype_helper(runtime_type, stub.type): | ||
| should_error = False | ||
| # We always allow setting the stub value to ... | ||
| # We always allow setting the stub value to Ellipsis (...), but use | ||
| # _value_ type as a fallback if given. If a member is ... and _value_ | ||
| # type is given, all runtime types should be assignable to _value_. | ||
| proper_type = mypy.types.get_proper_type(stub.type) | ||
| if ( | ||
| isinstance(proper_type, mypy.types.Instance) | ||
| and proper_type.type.fullname in mypy.types.ELLIPSIS_TYPE_NAMES | ||
| ): | ||
| should_error = False | ||
| value_t = stub.info.get("_value_") | ||
| if value_t is None or value_t.type is None or runtime_type is None: | ||
| should_error = False | ||
| elif is_subtype_helper(runtime_type, value_t.type): | ||
| should_error = False | ||
| else: | ||
| note = " (incompatible '_value_')" | ||
|
Collaborator
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. Is this intentionally making the
Collaborator
Author
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. I also tried thinking about that, couldn't invent a case where we have found an attribute but failed to interpret its
Collaborator
Author
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. Okay, almost all other checks do not reject "wtf" values as incompatible, updated for consistency. |
||
|
|
||
| if should_error: | ||
| yield Error( | ||
| object_path, f"variable differs from runtime type {runtime_type}", stub, runtime | ||
| object_path, | ||
| f"variable differs from runtime type {runtime_type}{note}", | ||
| stub, | ||
| runtime, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.