Skip to content

Internal error on processing NamedTuple with method and recursive field #8695

Closed
@michalbednarski

Description

@michalbednarski

Checking following code with mypy results in INTERNAL ERROR: maximum semantic analysis iteration count reached along with Deferral trace cycling with lines 7, 7 and -1

from typing import NamedTuple

class First(NamedTuple):
    def method(self):
        pass

class Second(NamedTuple):
    recursive: 'Second'

As far as I've debugged mypy code I think it is caused by analyze_class_body_common being called under save_namedtuple_body contextmanager which sets empty SymbolTable for class.
Then analyze_class_body_common processes methods defined in class body, method definition is processed through SemanticAnalyzer.visit_func_def which calls add_function_to_symbol_table.
Ultimately add_symbol_table_node upon not seeing that method was already handled (because we've cleared SymbolTable), sets SemanticAnalyzer#progress = True on every analysis iteration, preventing process_top_levels from setting final_iteration which breaks analysis cycle

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions