Skip to content

types.GenericAlias has extra __copy__ and __deepcopy__ in __dir__ #105487

Closed

Description

@sobolevn

Repro:

>>> type A[X] = list[X]
>>> dir(A[int])
[..., '__copy__', '__deepcopy__', ...]

We can access all other attributes, but not __copy__ and __deepcopy__:

>>> A[int].__copy__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'types.GenericAlias' object has no attribute '__copy__'. Did you mean: '__doc__'?

>>> A[int].__deepcopy__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'types.GenericAlias' object has no attribute '__deepcopy__'

I am not quite sure what is the right thing to do here 🤔

Linked PRs

Activity

  1. added a commit that references this issue on Jun 8, 2023
  2. hugovk commented on Nov 10, 2023

    @hugovk
    Member

    Thanks for the fix!

  3. asottile-sentry commented on Sep 5, 2025

    @asottile-sentry

    a little late to the party but __bases__ appears to not work as well:

    >>> '__bases__' in dir(list[str])
    True
    >>> list[str].__bases__
    Traceback (most recent call last):
      File "<python-input-15>", line 1, in <module>
        list[str].__bases__
    AttributeError: 'types.GenericAlias' object has no attribute '__bases__'. Did you mean: '__args__'?
  4. added a commit that references this issue on Sep 6, 2025
  5. sobolevn commented on Sep 6, 2025

    @sobolevn
    MemberAuthor

    Looks like the linked PR does something completely different. I created a new one.

  6. sobolevn commented on Sep 6, 2025

    @sobolevn
    MemberAuthor

    Thanks for the report!

  7. added 2 commits that reference this issue on Sep 6, 2025
  8. added a commit that references this issue on Sep 7, 2025
  9. added 2 commits that reference this issue on Sep 8, 2025
  10. added a commit that references this issue on Sep 9, 2025
  11. added a commit that references this issue on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions