Skip to content

New semantic analyzer: Clean-up logic for classes in functions #6422

Open
@ilevkivskyi

Description

@ilevkivskyi

While working on #6421 I looked again at logic for storing symbols for local (function- or method-level) classes in prepare_class_def(). The logic is too ad-hoc and needs to be cleaned up. Here are some points that should be fixed:

  • defn.fullname and info.fullname() should always coincide
  • info.fullname() prefix should coincide with the symbol table where the info is actually stored (for serialization)
  • things should work for double nested classes
  • things should work in fine-grained mode

I think the logic should be as following. Consider this example:

class Out:
    def meth(self) -> None:
        class In:
            def meth(self) -> None:
                class C: pass

The class C should be stored in its local namespace under name 'C'. In addition it should be stored in the namespace of __main__.Out under name 'C@5'. info.fullname() and defn.fullname should be both '__main__.Out.C@5'.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions