Skip to content

SymbolTableNode.kind conflates orthogonal characteristics #3440

Closed
@carljm

Description

@carljm

I encountered this issue in working on #3435 -- it is the reason that PR stops short of implementing support for module aliasing assignment outside of module global scope. When I remove the not self.is_module_scope() guard in that PR, this line in the added test fails with an opaque error A: main:5: error: Member "m2" is not assignable.

I haven't yet traced through to fully understand what is happening, but I have a strong suspicion that the problem is due to SymbolTableNode.kind representing orthogonal characteristics of the symbol table node with mutually exclusive enum values.

SymbolTableNode.kind can take one of these values: https://github.com/python/mypy/blob/master/mypy/nodes.py#L34-L53

This enum isn't capable of representing the fact that a MODULE_REF might occur at global, member, or local level. In the test linked above, I think the symbol table entry really should be both MDEF and MODULE_REF, but that isn't representable; when my code tries to change the class attribute symbol table node from MDEF to MODULE_REF, things break. I think mypy implicitly assumes that MODULE_REF is global.

Hopefully I can find time to explore this further, verify the suspicion, and investigate possible solutions. Just wanted to record my findings so far publicly before leaving PyCon sprint. Comments/guidance welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions