| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
I am not sure whether "single dispatch" or even "single dispatch method" should be written as a single word. |
Sorry, something went wrong.
I would prefer "single dispatch method" in text. Writing it as "singledispatchmethod" would match the name python object in functools, which would not be bad either. So both are fine with me This is what the output looks like now: <single dispatch method A.dp> <bound single dispatch method A.dp of <__main__.A object at 0x0000023B84D83A10>> <function A.normal at 0x0000023B84F2A090> <bound method A.normal of <__main__.A object at 0x0000023B84D83A10>> With script from functools import *
class A:
@singledispatchmethod
def dp(self, x):
return x
def normal(self, x):
return x
a = A()
print(repr(A.dp))
print(repr(a.dp))
print(repr(A.normal))
print(repr(a.normal))
I would change the representation of the A.dp to include the id. And maybe change the text from method to function? |
Sorry, something went wrong.
|
The difference between A.normal and A.dp is that A.normal is a long living object, while A.dp is a short-living temporary object which will usually disappear after the call, unless you keep a reference to it. And usually you do not have reason to keep a reference: if dp is a normal method, A.dp will not even work, unlike to the bound A().dp. It can only work if dp is a class or static method, but in that case it is easier to use a normal function with singledispatch. For function, the id can be needed to distinguish closures created by the same code that have the same name. So I do not think that there is a need to expose the id of the _singledispatchmethod_get object. The name should usually be enough. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.