Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor: Move Final check to elif branch and clean error string
  • Loading branch information
Vikash-Kumar-23 committed Feb 22, 2026
commit b997e14344e23e83985651e714856acf3c37b11c
17 changes: 8 additions & 9 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,15 +1279,6 @@ 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}",
stub,
runtime,
stub_desc=repr(stub.final_value),
)

if (
stub.is_initialized_in_class
and is_read_only_property(runtime)
Expand Down Expand Up @@ -1332,6 +1323,14 @@ def verify_var(
stub,
runtime,
)
elif 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",
Comment thread
hauntsaninja marked this conversation as resolved.
Outdated
stub,
runtime,
stub_desc=repr(stub.final_value),
)


@verify.register(nodes.OverloadedFuncDef)
Expand Down
10 changes: 5 additions & 5 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,17 +1174,17 @@ def read_write_attr(self, val): self._val = val
yield Case(
stub="""
from typing import Final
x_final: Final = 2
X_FINAL: Final = 2
""",
runtime="x_final = 1",
error="x_final",
runtime="X_FINAL = 1",
error="X_FINAL",
)
yield Case(
stub="""
from typing import Final
x_final_ok: Final = 1
X_FINAL_OK: Final = 1
""",
runtime="x_final_ok = 1",
runtime="X_FINAL_OK = 1",
error=None,
)

Expand Down