Skip to content

gh-144545: Improve handling of default values in Argument Clinic#146016

Merged
serhiy-storchaka merged 6 commits intopython:mainfrom
serhiy-storchaka:clinic-default-bytes-literal
Mar 17, 2026
Merged

gh-144545: Improve handling of default values in Argument Clinic#146016
serhiy-storchaka merged 6 commits intopython:mainfrom
serhiy-storchaka:clinic-default-bytes-literal

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 16, 2026

  • Add the c_init_default attribute which is used to initialize the C variable if the default is not explicitly provided.
  • Add the c_default_init() method which is used to derive c_default from default if c_default is not explicitly provided.
  • Explicit c_default and py_default are now almost always have precedence over the generated value.
  • Add support for bytes literals as default values.
  • Improve support for str literals as default values (support non-ASCII and non-printable characters and special characters like backslash).
  • Fix support for str and bytes literals containing trigraphs, "/" and "/".
  • Improve support for default values in converters "char" and "int(accept={str})".
  • Converter "int(accept={str})" now requires 1-character string instead of integer as default value.
  • Add support for non-None default values in converter "Py_buffer": NULL, str and bytes literals.
  • Improve error handling for invalid default values.

* Add the c_init_default attribute which is used to initialize the C variable
  if the default is not explicitly provided.
* Add the c_default_init() method which is used to derive c_default
  from default if c_default is not explicitly provided.
* Explicit c_default and py_default are now almost always have precedence
  over the generated value.
* Add support for bytes literals as default values.
* Improve support for str literals as default values (support non-ASCII and
  non-printable characters and special characters like backslash).
* Improved support for default values in converters "char" and
  "int(accept={str})".
* Add support for non-NULL default values in converter "Py_buffer".
* Improve error handling for invalid default values.
@serhiy-storchaka serhiy-storchaka merged commit 99e2c5e into python:main Mar 17, 2026
57 checks passed
@serhiy-storchaka serhiy-storchaka deleted the clinic-default-bytes-literal branch March 17, 2026 10:16
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label Mar 17, 2026
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 99e2c5eccd2b83ac955125522a952a4ff5c7eb43 3.14

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Mar 17, 2026
…t Clinic (pythonGH-146016)

* Add the c_init_default attribute which is used to initialize the C variable
  if the default is not explicitly provided.
* Add the c_default_init() method which is used to derive c_default from
  default if c_default is not explicitly provided.
* Explicit c_default and py_default are now almost always have precedence
  over the generated value.
* Add support for bytes literals as default values.
* Improve support for str literals as default values (support non-ASCII
  and non-printable characters and special characters like backslash or quotes).
* Fix support for str and bytes literals containing trigraphs, "/*" and "*/".
* Improve support for default values in converters "char" and "int(accept={str})".
* Converter "int(accept={str})" now requires 1-character string instead of
  integer as default value.
* Add support for non-None default values in converter "Py_buffer": NULL,
  str and bytes literals.
* Improve error handling for invalid default values.
* Rename Null to NullType for consistency.
(cherry picked from commit 99e2c5e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

GH-146052 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 17, 2026
@serhiy-storchaka serhiy-storchaka removed their assignment Mar 17, 2026
serhiy-storchaka added a commit that referenced this pull request Mar 17, 2026
…ic (GH-146016) (GH-146052)

* Add the c_init_default attribute which is used to initialize the C variable
  if the default is not explicitly provided.
* Add the c_default_init() method which is used to derive c_default from
  default if c_default is not explicitly provided.
* Explicit c_default and py_default are now almost always have precedence
  over the generated value.
* Add support for bytes literals as default values.
* Improve support for str literals as default values (support non-ASCII
  and non-printable characters and special characters like backslash or quotes).
* Fix support for str and bytes literals containing trigraphs, "/*" and "*/".
* Improve support for default values in converters "char" and "int(accept={str})".
* Converter "int(accept={str})" now requires 1-character string instead of
  integer as default value.
* Add support for non-None default values in converter "Py_buffer": NULL,
  str and bytes literals.
* Improve error handling for invalid default values.
* Rename Null to NullType for consistency.
(cherry picked from commit 99e2c5e)
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.

1 participant