eth-abi icon indicating copy to clipboard operation
eth-abi copied to clipboard

Consistent class or instance method usage in encoder

Open kclowes opened this issue 6 years ago • 1 comments

  • Version: 2.0.0

What was wrong?

When I was subclassing the eth-abi encoders in web3py, I noticed that in the Encoder inheritance tree, some of the validate_value methods are class methods and some are instance methods. For example, BooleanEncoder inherits from Fixed32ByteSizeEncoder which inherits from FixedSizeEncoder. BooleanEncoder's validate_value method is a class method and the FixedSizeEncoder's validate_value method is an instance method. Some of the other methods have the same problem.

How can it be fixed?

I think it probably makes sense to make most of them class methods since they are not changing the internal state of the class, but haven't looked to make sure that's true for all of the methods/classes.

kclowes avatar Aug 29 '19 22:08 kclowes

I seem to recall that the choice of instance vs. class method for all of those implementations was pretty deliberate. I think the issue was that, as calls to super bubble up the inheritance hierarchy, any call which originated from an instance method must have a reference to self available in order for the method resolution to be done correctly. I'll need to think of a way to confirm this because it's been a while since I had to deal with it.

davesque avatar Sep 04 '19 20:09 davesque

Stale

pacrob avatar Jul 01 '24 16:07 pacrob