Skip to content

Conversation

@njgheorghita
Copy link
Contributor

What was wrong?

w3.pm would raise a generic AttributeError rather than the intended AttributeError when checking for web3._pm if the attribute hadn't been set yet.

Cute Animal Picture

image

@property
def pm(self):
if self._pm is not None:
if hasattr(self, '_pm'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd be in favor of just having _pm = None defined on the class so that we don't have to do hasattr checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining _pm = None on the class causes a conflict with the way the PM module is eventually attached when running w3.enable_unaudited_package_management_api()

Cannot set <web3.main.Web3 object at 0x1050596d8> module named '_pm'. The web3 object already has an attribute with that name

It seems as though we can either hasattr check or change the way the PM module is attached to the w3 instance - currently ...

def enable_unaudited_package_management_api(self):
    PM.attach(self, '_pm')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasattr is fine 👍

@njgheorghita njgheorghita merged commit ca2e70a into ethereum:master Jan 28, 2019
@njgheorghita njgheorghita deleted the pm-api-bugfix branch January 28, 2019 08:30
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

Successfully merging this pull request may close these issues.

2 participants