Skip to content

Detect if an instance has __dict__ based on existence __slots__ #1325

Closed
@JukkaL

Description

@JukkaL

From python/typeshed#132 (comment) (@gvanrossum):

I think this may be undocumented but it's not meant to be varying by Python implementation -- the rule is that classes defined in extension modules don't have __dict__ but anything defined using a class statement has a __dict__ unless it defines __slots__ and all its base classes also don't have a __dict__.

Hm, that actually suggests a way to mark classes that doesn't require anything new in typing.py: we could add __slots__ to all classes that are supposed to be builtin (e.g. object, str, int) and mypy could implement a new rule that implicitly adds __dict__: Dict[str, Any] to any class definition that doesn't have __slots__.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions