Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improve typing._GenericAlias.__dir__ coverage #103395

Copy link
Copy link
Closed
@sobolevn

Description

@sobolevn
Issue body actions

Right now the only test we have for dir() on _GenericAlias is

    def test_genericalias_dir(self):
        class Foo(Generic[T]):
            def bar(self):
                pass
            baz = 3
        # The class attributes of the original class should be visible even
        # in dir() of the GenericAlias. See bpo-45755.
        self.assertIn('bar', dir(Foo[int]))
        self.assertIn('baz', dir(Foo[int]))

And here's how it is defined:

cpython/Lib/typing.py

Lines 1323 to 1325 in c330b4a

def __dir__(self):
return list(set(super().__dir__()
+ [attr for attr in dir(self.__origin__) if not _is_dunder(attr)]))

We clearly need more tests:

  1. That dunder methods are not included
  2. What _GenericAlias API we expose (at least parts that we consider user-visible, like __args__ and __parameters__ and __origin__)
  3. _GenericAlias has subclasses, they are also not tested

I will send a PR for this :)

Linked PRs

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.