Skip to content

[3.12] gh-117613: Argument Clinic: ensure that defining_class params are positional-only #117939

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

Merged
merged 9 commits into from
Apr 17, 2024

Conversation

neonene
Copy link
Contributor

@neonene neonene commented Apr 16, 2024

This is a backport of #117781 and #117950 to 3.12 branch.


3.12 and 3.13 have almost the same issue, but Modules/_sqlite/clinic/connection.c.h has correct NUM_KEYWORDS on 3.12 so far:

/*[clinic input]
_sqlite3.Connection.set_authorizer as pysqlite_connection_set_authorizer

    cls: defining_class
    /
    authorizer_callback as callable: object

Sets authorizer callback.
[clinic start generated code]*/

In old clinic.py, the case above invokes parse_special_symbol(), which overwrites the kind of defining_class from POSITIONAL_OR_KEYWORD to POSITIONAL_ONLY:

cpython/Tools/clinic/clinic.py

Lines 5073 to 5079 in aa26dc3

# fixup preceding parameters
for p in self.function.parameters.values():
if p.is_vararg():
continue
if (p.kind != inspect.Parameter.POSITIONAL_OR_KEYWORD and not isinstance(p.converter, self_converter)):
fail("Function " + self.function.name + " mixes keyword-only and positional-only parameters, which is unsupported.")
p.kind = inspect.Parameter.POSITIONAL_ONLY

Fixing defining_class params in state_parameter() can cause the parse_special_symbol() above to fail:

Error in file "connection.c" on line 1122:
Function create_function mixes keyword-only and positional-only parameters, which is unsupported.

This PR avoids the error as well.

@erlend-aasland
Copy link
Contributor

Good sleuthing, @neonene! I applied a style nit. Thank you so much!

@erlend-aasland erlend-aasland enabled auto-merge (squash) April 17, 2024 20:48
@erlend-aasland erlend-aasland merged commit 9f4ae13 into python:3.12 Apr 17, 2024
@neonene neonene deleted the ac312 branch April 18, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants