-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
stubtest: check Final variables with literal values against runtime #20858
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 1 commit
380d5d3
2cc6b43
b997e14
8949fd4
8d63f8e
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 |
|---|---|---|
|
|
@@ -1279,6 +1279,14 @@ def verify_var( | |
| yield Error(object_path, "is not present at runtime", stub, runtime) | ||
| return | ||
|
|
||
| if stub.final_value is not None and stub.final_value != runtime: | ||
| yield Error( | ||
| object_path, | ||
| f"is inconsistent, stub value {stub.final_value!r} differs from runtime value {runtime!r}", | ||
|
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. The runtime object could potentially have a very long repr, which we wouldn't want included in the error message. It's also already rendered in the output (with length truncation), so including in the message isn't necessary. |
||
| stub, | ||
| runtime, | ||
|
Vikash-Kumar-23 marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| if ( | ||
| stub.is_initialized_in_class | ||
| and is_read_only_property(runtime) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1171,6 +1171,22 @@ def read_write_attr(self, val): self._val = val | |
| """, | ||
| error=None, | ||
| ) | ||
| yield Case( | ||
| stub=""" | ||
| from typing import Final | ||
| x_final: Final = 2 | ||
|
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. style nit: maybe use |
||
| """, | ||
| runtime="x_final = 1", | ||
| error="x_final", | ||
| ) | ||
| yield Case( | ||
| stub=""" | ||
| from typing import Final | ||
| x_final_ok: Final = 1 | ||
| """, | ||
| runtime="x_final_ok = 1", | ||
| error=None, | ||
| ) | ||
|
|
||
| @collect_cases | ||
| def test_type_alias(self) -> Iterator[Case]: | ||
|
|
||
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.
Maybe move this to an elif branch of the subtype check below? That way we don't get duplicate errors when the types are different.