KEMBAR78
Consider adding `__slots__` to stubs? · Issue #8832 · python/typeshed · GitHub
Skip to content

Consider adding __slots__ to stubs? #8832

@sobolevn

Description

@sobolevn

Since mypy now supports __slots__ checking, we can add __slots__ to stubs.
This will allow us to correctly raise Something is not in __slots__ when assigning extra attributes.

Right now there are no __slots__ defined: https://github.com/python/typeshed/search?q=__slots__

If this is something we are going for, there are several things to consider:

  1. Adding this feature to stubtest. It can check that __slots__ contents do match. Probably behind a feature flag. We can enable it for stdlib only

  2. Should we allow skipping _protected attributes? For example, if some class is defined as

    class A:
       __slots__ = ('_prop',)

    Should we allow this stub?

    class A:
        __slots__ = ()

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