Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-104389: Add 'unused' keyword to Argument Clinic C converters #104390

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-104389: Argument Clinic now wraps unused args with Py_UNUSED
Use the unused keyword param in the converter to explicitly
mark an argument as unused:

    /*[clinic input]
    BaseClass.interface
        flag: bool(unused=True)
  • Loading branch information
erlend-aasland committed May 11, 2023
commit 2def279845116081759b35f56a6f4bbbcdfd6428
3 changes: 3 additions & 0 deletions 3 Doc/howto/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,9 @@ of these arguments, along with their meanings:

To accept ``None``, add ``NoneType`` to this set.

``unused``
Wrap the argument with :c:macro:`Py_UNUSED` in the impl function signature.

``bitwise``
Only supported for unsigned integers. The native integer value of this
Python argument will be written to the parameter without any range checking,
Expand Down
25 changes: 16 additions & 9 deletions 25 Modules/_io/clinic/textio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions 7 Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ _io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls)
/*[clinic input]
_io._TextIOBase.read
cls: defining_class
size: int(unused=True) = -1
/
*args: object

Read at most size characters from stream.

Expand All @@ -79,8 +79,9 @@ If size is negative or omitted, read until EOF.
[clinic start generated code]*/

static PyObject *
_io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
/*[clinic end generated code: output=3adf28998831f461 input=cee1e84664a20de0]*/
_io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls,
int Py_UNUSED(size))
/*[clinic end generated code: output=51a5178a309ce647 input=f5e37720f9fc563f]*/
{
_PyIO_State *state = IO_STATE();
return _unsupported(state, "read");
Expand Down
20 changes: 19 additions & 1 deletion 20 Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,9 @@ class CConverter(metaclass=CConverterAutoRegister):
# Every non-abstract subclass should supply a valid value.
c_ignored_default = 'NULL'

# If true, wrap with Py_UNUSED.
unused = False

# The C converter *function* to be used, if any.
# (If this is not None, format_unit must be 'O&'.)
converter = None
Expand Down Expand Up @@ -2651,9 +2654,22 @@ class CConverter(metaclass=CConverterAutoRegister):
signature_name = None

# keep in sync with self_converter.__init__!
def __init__(self, name, py_name, function, default=unspecified, *, c_default=None, py_default=None, annotation=unspecified, **kwargs):
def __init__(self,
# Positional args:
name,
py_name,
function,
default=unspecified,
*, # Keyword only args:
c_default=None,
py_default=None,
annotation=unspecified,
unused=False,
**kwargs
):
self.name = ensure_legal_c_identifier(name)
self.py_name = py_name
self.unused = unused

if default is not unspecified:
if self.default_type and not isinstance(default, (self.default_type, Unknown)):
Expand Down Expand Up @@ -2800,6 +2816,8 @@ def simple_declaration(self, by_reference=False, *, in_parser=False):
name = self.parser_name
else:
name = self.name
if self.unused:
name = f"Py_UNUSED({name})"
prototype.append(name)
return "".join(prototype)

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.