Skip to content

Cannot copy class inheriting from generic #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mitar opened this issue Aug 14, 2017 · 2 comments
Closed

Cannot copy class inheriting from generic #458

mitar opened this issue Aug 14, 2017 · 2 comments

Comments

@mitar
Copy link
Contributor

mitar commented Aug 14, 2017

Example:

Python 3.6.2 (default, Jul 17 2017, 16:44:32) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> class Foo(typing.Sequence):
...   pass
... 
>>> Foo.__copy__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 1189, in __copy__
    self.__extra__, self.__orig_bases__)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 953, in __new__
    assert origin is not None
AssertionError
>>> typing.Sequence.__copy__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 1189, in __copy__
    self.__extra__, self.__orig_bases__)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 953, in __new__
    assert origin is not None
AssertionError
>>> typing.Sequence[typing.T_co].__copy__()
typing.Sequence[+T_co]
@mitar
Copy link
Contributor Author

mitar commented Aug 14, 2017

As you see, also unbound generic cannot be copied.

@ilevkivskyi
Copy link
Member

You should never call __copy__ directly, it only exists for backwards compatibility with Python 3.2 (which was removed recently due to Python 3.2 reaching EoL, so that __copy__ could be actually removed at any time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants