Skip to content

Argument Clinic docstring generator ignores a custom name for $module argument #94246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arhadthedev opened this issue Jun 24, 2022 · 2 comments
Labels
topic-argument-clinic type-bug An unexpected behavior, bug, or error

Comments

@arhadthedev
Copy link
Member

arhadthedev commented Jun 24, 2022

Input file

/*[clinic input]
my_method
    _foo: self(type="PyObject *")
    module: object
[clinic start generated code]*/

python Tools/clinic/clinic.py test.c

Current result

/*[clinic input]
preserve
[clinic start generated code]*/

PyDoc_STRVAR(my_method__doc__,
"my_method($module, /, module)\n"
"--\n"
"\n");

[snip]

my_method__doc__ continues to list renamed _foo as $module.

Expected result

-"my_method($module, /, module)\n"
+"my_method($_foo, /, module)\n"

A docstring should use an actual module/self variable name to not confuse docstring readers; its special role is denoted by $ prefix and position anyway.

This issue is a blocker for #92891 (comment).

@arhadthedev
Copy link
Member Author

arhadthedev commented Jun 24, 2022

I localized the issue. Function format_docstring renders a docstring variable name using the following logic:

cpython/Tools/clinic/clinic.py

Lines 4975 to 4976 in 605e9c6

name = p.converter.signature_name or p.name
p_add(name)

For our two parameters, values are the following:

  • p.converter.signature_name='module', p.name='_foo'
  • p.converter.signature_name=None`, p.name='module'

In other words, the clinic seems to implicitly append ... as module to whatever we declare with self(...). And, alas, self_converter.pre_render does exactly this (line 3675):

cpython/Tools/clinic/clinic.py

Lines 3672 to 3682 in 605e9c6

def pre_render(self):
f = self.function
default_type, default_name = correct_name_for_self(f)
self.signature_name = default_name
self.type = self.specified_type or self.type or default_type
kind = self.function.kind
new_or_init = kind in (METHOD_NEW, METHOD_INIT)
if (kind == STATIC_METHOD) or new_or_init:
self.show_in_signature = False

Is there any reason to prefer default names over the custom ones?

@arhadthedev arhadthedev changed the title Argument Clinic docstring generator ignores a custom name for module argument Argument Clinic docstring generator ignores a custom name for $module argument Jun 25, 2022
@arhadthedev
Copy link
Member Author

arhadthedev commented Jun 29, 2022

Closing in favor of gh-94430 as a proper fix.

@erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-argument-clinic type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants