Skip to content
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

subclassing safe doesn't work #972

Closed
banteg opened this issue May 9, 2024 · 3 comments · Fixed by #992
Closed

subclassing safe doesn't work #972

banteg opened this issue May 9, 2024 · 3 comments · Fixed by #992
Assignees
Labels
bug Something isn't working

Comments

@banteg
Copy link
Contributor

banteg commented May 9, 2024

return super().__new__(cls, address, ethereum_client, *args, **kwargs)

/gnosis/safe/safe.py", line 96, in __new__
    return super().__new__(cls, address, ethereum_client, *args, **kwargs)
TypeError: object.__new__() takes exactly one argument (the type to instantiate)
@Uxio0
Copy link
Member

Uxio0 commented May 10, 2024

Could you provide some info? We subclass Safe without further issues, like:

class SafeV130(Safe):

@banteg
Copy link
Contributor Author

banteg commented May 10, 2024

i think it has something to do with how __new__ is overriden, maybe it should just be a normal function that creates an appropriate safe from address and client.

In [1]: from gnosis.eth import EthereumClient

In [2]: from gnosis.safe.safe import SafeV130, Safe

In [3]: client = EthereumClient()

In [4]: addr = '0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52'

In [5]: class MySafe(Safe):
   ...:     pass
   ...:

In [6]: class MySafeV130(SafeV130):
   ...:     pass
   ...:

In [7]: Safe(addr, client)
Out[7]: <gnosis.safe.safe.SafeV130 at 0x107a9b790>

In [8]: SafeV130(addr, client)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[8], line 1
----> 1 SafeV130(addr, client)

File ~/yearn/brownie-safe/.venv/lib/python3.10/site-packages/gnosis/safe/safe.py:95, in Safe.__new__(cls, address, ethereum_client, *args, **kwargs)
     93 assert fast_is_checksum_address(address), "%s is not a valid address" % address
     94 if cls is not Safe:
---> 95     return super().__new__(cls, address, ethereum_client, *args, **kwargs)
     97 versions: Dict[str, Safe] = {
     98     "0.0.1": SafeV001,
     99     "1.0.0": SafeV100,
   (...)
    103     "1.4.1": SafeV141,
    104 }
    105 default_version = SafeV141

TypeError: object.__new__() takes exactly one argument (the type to instantiate)

In [9]: MySafe(addr, client)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[9], line 1
----> 1 MySafe(addr, client)

File ~/yearn/brownie-safe/.venv/lib/python3.10/site-packages/gnosis/safe/safe.py:95, in Safe.__new__(cls, address, ethereum_client, *args, **kwargs)
     93 assert fast_is_checksum_address(address), "%s is not a valid address" % address
     94 if cls is not Safe:
---> 95     return super().__new__(cls, address, ethereum_client, *args, **kwargs)
     97 versions: Dict[str, Safe] = {
     98     "0.0.1": SafeV001,
     99     "1.0.0": SafeV100,
   (...)
    103     "1.4.1": SafeV141,
    104 }
    105 default_version = SafeV141

TypeError: object.__new__() takes exactly one argument (the type to instantiate)

In [10]: MySafeV130(addr, client)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[10], line 1
----> 1 MySafeV130(addr, client)

File ~/yearn/brownie-safe/.venv/lib/python3.10/site-packages/gnosis/safe/safe.py:95, in Safe.__new__(cls, address, ethereum_client, *args, **kwargs)
     93 assert fast_is_checksum_address(address), "%s is not a valid address" % address
     94 if cls is not Safe:
---> 95     return super().__new__(cls, address, ethereum_client, *args, **kwargs)
     97 versions: Dict[str, Safe] = {
     98     "0.0.1": SafeV001,
     99     "1.0.0": SafeV100,
   (...)
    103     "1.4.1": SafeV141,
    104 }
    105 default_version = SafeV141

TypeError: object.__new__() takes exactly one argument (the type to instantiate)

@Uxio0
Copy link
Member

Uxio0 commented May 30, 2024

@banteg we have just released a new version with this bug fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants