Skip to content

Missing attributes for MappingView and subclasses in stdlib/collections_abc_.pyi #7576

Closed as not planned
@laundmo

Description

@laundmo

Due to stdlib/_collections_abc.pyi importing most directly from stdlib/typing.pyi, MappingView and its subclasses are missing the self._mapping attribute. This is an issue if inheriting from them for implementing custom views. This causes pyright and mypy (with --check-untyped-defs) to fail.

Minimal Example:

import collections.abc

class MyView(collections.abc.KeysView):
    def __iter__(self):
        for key in self._mapping:
            yield key + 1

mypy --check-untyped-defs test.py

test.py:5: error: "MyView" has no attribute "_mapping"

pyright test.py

test.py
  test.py:5:25 - error: Cannot access member "_mapping" for type "MyView"
    Member "_mapping" is unknown (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations

I'm open to trying to PR this myself, though I have little experience writing stub files.

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