Skip to content

Commit a0665e1

Browse files
authored
Fix "ignored exception in hasattr" in dmypy (#19428)
Fixes #19425. That property has no setter so it should safe to exclude. It can raise in inconsistent state that arises when it is not copied last?
1 parent abb1cc7 commit a0665e1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

mypy/server/astmerge.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,11 @@ def visit_type_alias(self, node: TypeAlias) -> None:
345345
def fixup(self, node: SN) -> SN:
346346
if node in self.replacements:
347347
new = self.replacements[node]
348-
skip_slots: tuple[str, ...] = ()
349348
if isinstance(node, TypeInfo) and isinstance(new, TypeInfo):
350349
# Special case: special_alias is not exposed in symbol tables, but may appear
351350
# in external types (e.g. named tuples), so we need to update it manually.
352-
skip_slots = ("special_alias",)
353351
replace_object_state(new.special_alias, node.special_alias)
354-
replace_object_state(new, node, skip_slots=skip_slots)
352+
replace_object_state(new, node, skip_slots=_get_ignored_slots(new))
355353
return cast(SN, new)
356354
return node
357355

@@ -556,9 +554,16 @@ def replace_nodes_in_symbol_table(
556554
if node.node in replacements:
557555
new = replacements[node.node]
558556
old = node.node
559-
# Needed for TypeInfo, see comment in fixup() above.
560-
replace_object_state(new, old, skip_slots=("special_alias",))
557+
replace_object_state(new, old, skip_slots=_get_ignored_slots(new))
561558
node.node = new
562559
if isinstance(node.node, (Var, TypeAlias)):
563560
# Handle them here just in case these aren't exposed through the AST.
564561
node.node.accept(NodeReplaceVisitor(replacements))
562+
563+
564+
def _get_ignored_slots(node: SymbolNode) -> tuple[str, ...]:
565+
if isinstance(node, OverloadedFuncDef):
566+
return ("setter",)
567+
if isinstance(node, TypeInfo):
568+
return ("special_alias",)
569+
return ()

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ addopts = "-nauto --strict-markers --strict-config"
222222
# treat xpasses as test failures so they get converted to regular tests as soon as possible
223223
xfail_strict = true
224224

225+
# Force warnings as errors
226+
filterwarnings = [
227+
"error",
228+
# Some testcases may contain code that emits SyntaxWarnings, and they are not yet
229+
# handled consistently in 3.14 (PEP 765)
230+
"default::SyntaxWarning",
231+
]
232+
225233
[tool.coverage.run]
226234
branch = true
227235
source = ["mypy"]

0 commit comments

Comments
 (0)