coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
277 stars 24 forks source link

fix: Check that homonym is a multimethod when getting the base multimethod object #27

Closed plammens closed 3 years ago

plammens commented 3 years ago

This fixes an issue where a new multimethod whose name collides with an unrelated variable or function in the same namespace would return that as the result of the decoration.

coady commented 3 years ago

Interesting, this is related to discussion #12. If relying on the magic namespace lookup is the preferred style, then it could be argued this should raise an error. Whereas if one's planning on using register, then it should definitely behave like any Python object.

Either way, this is an improvement. Thanks.

plammens commented 3 years ago

If relying on the magic namespace lookup is the preferred style, then it could be argued this should raise an error.

I agree, but then, even if one is strictly using register only, the first function (decorated with @multimethod) would raise an error if the name was already present in the namespace (with an unrelated value), since this logic is in __new__; so the register way would have to be aware of the magic namespace lookup way, so to speak. But maybe this is also desirable behaviour.