ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.95k stars 1.69k forks source link

Add `pop` method to `web3.datastructures.AttributeDict` #3326

Closed antazoey closed 5 months ago

antazoey commented 5 months ago

What feature should we add?

Right now, this confusingly fails:

data = eth_tester_provider.web3.eth.get_block("latest")
size = data.pop("size", None)

AttributeError: 'AttributeDict' object has no attribute 'pop'

My workaround is this:

data = {**eth_tester_provider.web3.eth.get_block("latest")}
size = data.pop("size", None)

My feature request is to add the pop method to AttributeDict so it works the same as regular dicts in that regard.

pacrob commented 5 months ago

AttributeDict was created with the idea that it should be immutable. It seems like if you want to pop things from it, copying then popping would be the way to go.