Closed deknowny closed 2 years ago
Thank you for the report @deknowny!
The __handler
parameter is documented using the right name because it's written explicitly in the Arguments section.
The _Bot__handler
in the signature is how inspect
resolves its name. Maybe it's a bug in inspect
? I don't think function arguments names are supposed to be changed the same way class/instance attributes are.
>>> class A:
... def hello(self, __arg: int):
... return str(__arg)
...
>>> import inspect
>>> inspect.signature(A.hello)
<Signature (self, _A__arg: int)>
I'll see if I can find a bug report on inspect
, or a rationale for this behavior.
Couldn't find anything on the subject yet. In the meantime, I suggest you don't prefix method/function parameters with double-underscores :confused: Why the double underscores by the way? Just being curious :slightly_smiling_face:
Thanks for answering! I use two underscores in argument's name to define it as positional only. Unfortunately, using /
for that is available only with python 3.8 and later but I need to support versions lower
Oh okay, so it seems to be the expected behavior, as Python itself changes the argument name to _Bot__handler
. inspect
has nothing to do with this.
>>> class A:
... def run(self, __arg):
... return __arg
...
>>> a = A()
>>> a.run(__arg=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: run() got an unexpected keyword argument '__arg'
>>> a.run(_A__arg=0)
0
Well, there's nothing we can do in mkdocstrings or pytkdocs then, unless we start trying to replace parameters name based on their class name, which would be messy I fear :confused: I would be glad to hear any other idea for a solution to this though!
This is likely solved by the new handler. Feedback appreciated!
When my function's argument starts with 2 underscores, it has another representation and typing hints missed