You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my code I am subclassing int to add an extra attribute, using something like this code:
fromtypingimportAnyclassMyInt(int):
'''Subclass of int with an extra attribute'''def__new__(cls: type, value: int, extra_attr: Any) ->'MyInt':
# Offending linenewval=super(MyInt, cls).__new__(cls, value)
newval.extra_attr=extra_attrreturnnewvaldef__repr__(self) ->str:
return'MyInt(value={value!r}, extra_attr={extra_attr!r})'.format(
value=int(self),
extra_attr=self.extra_attr,
)
# MyInt should work like an intx=MyInt(5, "hello")
print(repr(x))
x==5x*2x+1
However, mypy doesn't like the call to super(...).__new__:
$ mypy ~/temp/test_mypy.py
temp/test_mypy.py:7: error: Argument 2 for "super" not an instance of argument 1
temp/test_mypy.py:7: error: Too many arguments for "__new__" of "object"
temp/test_mypy.py:14: error: "MyInt" has no attribute "extra_attr"
$ mypy --version
pmypy 0.650
$ python --version
Python 3.7.1
As far as I know, this is the correct way to implement MyInt.__new__, and if I understand correctly, super(MyInt, cls).__new__ should be resolving to int.__new__, not object.__new__.
I believe this is the same bug that was mentioned here and suggested to be reported as a separate issue: #794 (comment)
The text was updated successfully, but these errors were encountered:
In my code I am subclassing int to add an extra attribute, using something like this code:
However, mypy doesn't like the call to
super(...).__new__
:As far as I know, this is the correct way to implement
MyInt.__new__
, and if I understand correctly,super(MyInt, cls).__new__
should be resolving toint.__new__
, notobject.__new__
.I believe this is the same bug that was mentioned here and suggested to be reported as a separate issue: #794 (comment)
The text was updated successfully, but these errors were encountered: