Skip to content

Error when accessing attribute of inner class #3635

Closed
@rowillia

Description

@rowillia

test_inner_class_attribute.py:

class Foo:
    class Meta:
        name = 'Roy'

print(Foo().Meta.name)

Python executes the code just fine:

$ python3.6 test_inner_class_attribute.py
Roy

But mypy fails to typecheck

$ mypy test_inner_class_attribute.py
test_inner_class_attribute.py:5: error: Member "Meta" is not assignable

This pattern is super common in the Django Rest Framework, Marshmallow, and PynamoDB projects (Probably more that I don't know about as well 😄 )

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