Skip to content

Fix "ignored exception in hasattr" in dmypy #19428

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

Merged
merged 3 commits into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,11 @@ def visit_type_alias(self, node: TypeAlias) -> None:
def fixup(self, node: SN) -> SN:
if node in self.replacements:
new = self.replacements[node]
skip_slots: tuple[str, ...] = ()
if isinstance(node, TypeInfo) and isinstance(new, TypeInfo):
# Special case: special_alias is not exposed in symbol tables, but may appear
# in external types (e.g. named tuples), so we need to update it manually.
skip_slots = ("special_alias",)
replace_object_state(new.special_alias, node.special_alias)
replace_object_state(new, node, skip_slots=skip_slots)
replace_object_state(new, node, skip_slots=_get_ignored_slots(new))
return cast(SN, new)
return node

Expand Down Expand Up @@ -556,9 +554,16 @@ def replace_nodes_in_symbol_table(
if node.node in replacements:
new = replacements[node.node]
old = node.node
# Needed for TypeInfo, see comment in fixup() above.
replace_object_state(new, old, skip_slots=("special_alias",))
replace_object_state(new, old, skip_slots=_get_ignored_slots(new))
node.node = new
if isinstance(node.node, (Var, TypeAlias)):
# Handle them here just in case these aren't exposed through the AST.
node.node.accept(NodeReplaceVisitor(replacements))


def _get_ignored_slots(node: SymbolNode) -> tuple[str, ...]:
if isinstance(node, OverloadedFuncDef):
return ("setter",)
if isinstance(node, TypeInfo):
return ("special_alias",)
return ()
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ addopts = "-nauto --strict-markers --strict-config"
# treat xpasses as test failures so they get converted to regular tests as soon as possible
xfail_strict = true

# Force warnings as errors
filterwarnings = [
"error",
# Some testcases may contain code that emits SyntaxWarnings, and they are not yet
# handled consistently in 3.14 (PEP 765)
"default::SyntaxWarning",
]

[tool.coverage.run]
branch = true
source = ["mypy"]
Expand Down