Skip to content

my_var: self.SubClass type hint returns Variable not allowed in type expression #132004

@turbonate

Description

@turbonate

Bug report

Bug description:

class MyClass:
    class MyTreeSubClass:
        def __init___():
            self.children = []
        def addchild(foo):
            self.children.append(foo)
        def postorder_traversal():
            for child in children:
               yield from child.postorder_traversal()
            yield self

    def bar():
        baz = self.MyTreeSubClass()
        #init baz logic here
        for node in baz.postorder_traversal():
            node: self.MyTreeSubClass #Variable not allwed in type expression
            node.what_even_am_i()

I can't do a self.SubClass type hint because self is not allowed in type hinting.

this line is the issue:
node: self.MyTreeSubClass #Variable not allwed in type expression

CPython versions tested on:

3.12

Operating systems tested on:

Windows

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