diff --git a/Doc/distutils/introduction.rst b/Doc/distutils/introduction.rst index 8f46bd74c5b01a..a38555910361b8 100644 --- a/Doc/distutils/introduction.rst +++ b/Doc/distutils/introduction.rst @@ -193,8 +193,8 @@ modules using the Distutils: module distribution a collection of Python modules distributed together as a single downloadable resource and meant to be installed *en masse*. Examples of some well-known - module distributions are NumPy, SciPy, PIL (the Python Imaging - Library), or mxBase. (This would be called a *package*, except that term is + module distributions are NumPy, SciPy, Pillow, + or mxBase. (This would be called a *package*, except that term is already taken in the Python context: a single module distribution may contain zero, one, or many Python packages.) diff --git a/Doc/extending/newtypes_tutorial.rst b/Doc/extending/newtypes_tutorial.rst index ac48637bbee9be..bb8a40d0fb06f5 100644 --- a/Doc/extending/newtypes_tutorial.rst +++ b/Doc/extending/newtypes_tutorial.rst @@ -457,7 +457,7 @@ We define a single method, :meth:`Custom.name()`, that outputs the objects name concatenation of the first and last names. :: static PyObject * - Custom_name(CustomObject *self) + Custom_name(CustomObject *self, PyObject *Py_UNUSED(ignored)) { if (self->first == NULL) { PyErr_SetString(PyExc_AttributeError, "first"); diff --git a/Doc/installing/index.rst b/Doc/installing/index.rst index f9a224be92b8be..9f9f5a070b269e 100644 --- a/Doc/installing/index.rst +++ b/Doc/installing/index.rst @@ -62,11 +62,6 @@ Key terms of the mailing list used to coordinate Python packaging standards development). -.. deprecated:: 3.6 - ``pyvenv`` was the recommended tool for creating virtual environments for - Python 3.3 and 3.4, and is `deprecated in Python 3.6 - `_. - .. versionchanged:: 3.5 The use of ``venv`` is now recommended for creating virtual environments. diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 5da5cd9f96d93f..f51c580c0de1c0 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -1120,6 +1120,11 @@ ConfigParser Objects given *section*. Optional arguments have the same meaning as for the :meth:`get` method. + .. versionchanged:: 3.8 + Items present in *vars* no longer appear in the result. The previous + behaviour mixed actual parser options with variables provided for + interpolation. + .. method:: set(section, option, value) diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index abd0d5fa0fdf97..9c7ea2bdb7b68b 100644 --- a/Doc/library/contextvars.rst +++ b/Doc/library/contextvars.rst @@ -8,7 +8,7 @@ -------------- -This module provides APIs to manage, store, and access non-local +This module provides APIs to manage, store, and access context-local state. The :class:`~contextvars.ContextVar` class is used to declare and work with *Context Variables*. The :func:`~contextvars.copy_context` function and the :class:`~contextvars.Context` class should be used to diff --git a/Doc/library/email.generator.rst b/Doc/library/email.generator.rst index cc8e8225a203ab..2575a51300705f 100644 --- a/Doc/library/email.generator.rst +++ b/Doc/library/email.generator.rst @@ -185,7 +185,7 @@ to be using :class:`BytesGenerator`, and not :class:`Generator`. Convert any bytes with the high bit set as needed using an ASCII-compatible :mailheader:`Content-Transfer-Encoding`. That is, transform parts with non-ASCII :mailheader:`Cotnent-Transfer-Encoding` - (:mailheader:`Content-Transfer-Encoding: 8bit`) to an ASCII compatibile + (:mailheader:`Content-Transfer-Encoding: 8bit`) to an ASCII compatible :mailheader:`Content-Transfer-Encoding`, and encode RFC-invalid non-ASCII bytes in headers using the MIME ``unknown-8bit`` character set, thus rendering them RFC-compliant. diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index bc4316fabaee58..7db6ca68b23ca0 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -247,9 +247,10 @@ attributes: .. function:: getmembers(object[, predicate]) - Return all the members of an object in a list of (name, value) pairs sorted by - name. If the optional *predicate* argument is supplied, only members for which - the predicate returns a true value are included. + Return all the members of an object in a list of ``(name, value)`` + pairs sorted by name. If the optional *predicate* argument—which will be + called with the ``value`` object of each member—is supplied, only members + for which the predicate returns a true value are included. .. note:: diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index 8b3081cb80c972..504f3a1c3c33bf 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -735,8 +735,9 @@ For an example of the usage of queues for interprocess communication see .. function:: Pipe([duplex]) - Returns a pair ``(conn1, conn2)`` of :class:`Connection` objects representing - the ends of a pipe. + Returns a pair ``(conn1, conn2)`` of + :class:`~multiprocessing.connection.Connection` objects representing the + ends of a pipe. If *duplex* is ``True`` (the default) then the pipe is bidirectional. If *duplex* is ``False`` then the pipe is unidirectional: ``conn1`` can only be @@ -1021,10 +1022,13 @@ Miscellaneous Connection Objects ~~~~~~~~~~~~~~~~~~ +.. currentmodule:: multiprocessing.connection + Connection objects allow the sending and receiving of picklable objects or strings. They can be thought of as message oriented connected sockets. -Connection objects are usually created using :func:`Pipe` -- see also +Connection objects are usually created using +:func:`Pipe ` -- see also :ref:`multiprocessing-listeners-clients`. .. class:: Connection @@ -1159,6 +1163,8 @@ For example: Synchronization primitives ~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. currentmodule:: multiprocessing + Generally synchronization primitives are not as necessary in a multiprocess program as they are in a multithreaded program. See the documentation for :mod:`threading` module. @@ -2269,7 +2275,7 @@ Listeners and Clients :synopsis: API for dealing with sockets. Usually message passing between processes is done using queues or by using -:class:`~multiprocessing.Connection` objects returned by +:class:`~Connection` objects returned by :func:`~multiprocessing.Pipe`. However, the :mod:`multiprocessing.connection` module allows some extra @@ -2299,7 +2305,7 @@ multiple connections at the same time. .. function:: Client(address[, family[, authkey]]) Attempt to set up a connection to the listener which is using address - *address*, returning a :class:`~multiprocessing.Connection`. + *address*, returning a :class:`~Connection`. The type of the connection is determined by *family* argument, but this can generally be omitted since it can usually be inferred from the format of @@ -2349,8 +2355,8 @@ multiple connections at the same time. .. method:: accept() Accept a connection on the bound socket or named pipe of the listener - object and return a :class:`~multiprocessing.Connection` object. If - authentication is attempted and fails, then + object and return a :class:`~Connection` object. + If authentication is attempted and fails, then :exc:`~multiprocessing.AuthenticationError` is raised. .. method:: close() @@ -2386,7 +2392,7 @@ multiple connections at the same time. For both Unix and Windows, an object can appear in *object_list* if it is - * a readable :class:`~multiprocessing.Connection` object; + * a readable :class:`~multiprocessing.connection.Connection` object; * a connected and readable :class:`socket.socket` object; or * the :attr:`~multiprocessing.Process.sentinel` attribute of a :class:`~multiprocessing.Process` object. @@ -2509,10 +2515,10 @@ an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address. Authentication keys ~~~~~~~~~~~~~~~~~~~ -When one uses :meth:`Connection.recv `, the +When one uses :meth:`Connection.recv `, the data received is automatically -unpickled. Unfortunately unpickling data from an untrusted source is a security -risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module +unpickled. Unfortunately unpickling data from an untrusted source is a security +risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module to provide digest authentication. An authentication key is a byte string which can be thought of as a diff --git a/Doc/library/os.rst b/Doc/library/os.rst index d269d0b0eaa6ce..2f3b31edd5d704 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1126,18 +1126,24 @@ or `the MSDN `_ on Windo .. versionadded:: 3.7 -.. data:: RWF_DSYNC (since Linux 4.7) +.. data:: RWF_DSYNC + Provide a per-write equivalent of the O_DSYNC open(2) flag. This flag is meaningful only for pwritev2(), and its effect applies only to the data range written by the system call. + Availability: Linux (version 4.7). + .. versionadded:: 3.7 -.. data:: RWF_SYNC (since Linux 4.7) +.. data:: RWF_SYNC + Provide a per-write equivalent of the O_SYNC open(2) flag. This flag is meaningful only for pwritev2(), and its effect applies only to the data range written by the system call. + Availability: Linux (version 4.7). + .. versionadded:: 3.7 @@ -1260,16 +1266,20 @@ or `the MSDN `_ on Windo .. versionadded:: 3.7 -.. data:: RWF_HIPRI (since Linux 4.6) +.. data:: RWF_HIPRI + High priority read/write. Allows block-based filesystems to use polling of the device, which provides lower latency, but may use additional resources. (Currently, this feature is usable only on a file descriptor opened using the O_DIRECT flag.) + Availability: Linux (version 4.6). + .. versionadded:: 3.7 -.. data:: RWF_NOWAIT (since Linux 4.14) +.. data:: RWF_NOWAIT + Do not wait for data which is not immediately available. If this flag is specified, the preadv2() system call will return instantly if it would have to read data from the backing storage or wait for a lock. @@ -1277,6 +1287,8 @@ or `the MSDN `_ on Windo read. If no bytes were read, it will return -1 and set errno to EAGAIN. Currently, this flag is meaningful only for preadv2(). + Availability: Linux (version 4.14). + .. versionadded:: 3.7 diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 7b0971a83bcb6e..aeeed0042fce90 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -746,7 +746,7 @@ The :mod:`test.support` module defines the following functions: .. function:: wait_threads_exit(timeout=60.0) - Context manager to wait until all threads created in the ``with`` statment + Context manager to wait until all threads created in the ``with`` statement exit. diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index b99dc8ec276272..d9c1c35aa294bd 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -13,12 +13,17 @@ The :mod:`tkinter` package ("Tk interface") is the standard Python interface to the Tk GUI toolkit. Both Tk and :mod:`tkinter` are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it -is maintained at ActiveState.) You can check that :mod:`tkinter` is properly -installed on your system by running ``python -m tkinter`` from the command line; -this should open a window demonstrating a simple Tk interface. +is maintained at ActiveState.) + +Running ``python -m tkinter`` from the command line should open a window +demonstrating a simple Tk interface, letting you know that :mod:`tkinter` is +properly installed on your system, and also showing what version of Tcl/Tk is +installed, so you can read the Tcl/Tk documentation specific to that version. .. seealso:: + Tkinter documentation: + `Python Tkinter Resources `_ The Python Tkinter Topic Guide provides a great deal of information on using Tk from Python and links to other sources of information on Tk. @@ -32,9 +37,6 @@ this should open a window demonstrating a simple Tk interface. `Tkinter docs from effbot `_ Online reference for tkinter supported by effbot.org. - `Tcl/Tk manual `_ - Official manual for the latest tcl/tk version. - `Programming Python `_ Book by Mark Lutz, has excellent coverage of Tkinter. @@ -42,7 +44,25 @@ this should open a window demonstrating a simple Tk interface. Book by Mark Rozerman about building attractive and modern graphical user interfaces with Python and Tkinter. `Python and Tkinter Programming `_ - The book by John Grayson (ISBN 1-884777-81-3). + Book by John Grayson (ISBN 1-884777-81-3). + + Tcl/Tk documentation: + + `Tk commands `_ + Most commands are available as :mod:`tkinter` or :mod:`tkinter.ttk` classes. + Change '8.6' to match the version of your Tcl/Tk installation. + + `Tcl/Tk recent man pages `_ + Recent Tcl/Tk manuals on www.tcl.tk. + + `ActiveState Tcl Home Page `_ + The Tk/Tcl development is largely taking place at ActiveState. + + `Tcl and the Tk Toolkit `_ + Book by John Ousterhout, the inventor of Tcl. + + `Practical Programming in Tcl and Tk `_ + Brent Welch's encyclopedic book. Tkinter Modules @@ -175,21 +195,6 @@ documentation that exists. Here are some hints: place to go when nothing else makes sense. -.. seealso:: - - `Tcl/Tk 8.6 man pages `_ - The Tcl/Tk manual on www.tcl.tk. - - `ActiveState Tcl Home Page `_ - The Tk/Tcl development is largely taking place at ActiveState. - - `Tcl and the Tk Toolkit `_ - The book by John Ousterhout, the inventor of Tcl. - - `Practical Programming in Tcl and Tk `_ - Brent Welch's encyclopedic book. - - A Simple Hello World Program ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -800,6 +805,10 @@ reference to the image. When the last Python reference to the image object is deleted, the image data is deleted as well, and Tk will display an empty box wherever the image was used. +.. seealso:: + + The `Pillow `_ package adds support for + formats such as BMP, JPEG, TIFF, and WebP, among others. .. _tkinter-file-handlers: diff --git a/Doc/library/venv.rst b/Doc/library/venv.rst index 6707be7fc820dd..1fff7bc4bfb22b 100644 --- a/Doc/library/venv.rst +++ b/Doc/library/venv.rst @@ -23,10 +23,6 @@ independent set of installed Python packages in its site directories. See :pep:`405` for more information about Python virtual environments. -.. note:: - The ``pyvenv`` script has been deprecated as of Python 3.6 in favor of using - ``python3 -m venv`` to help prevent any potential confusion as to which - Python interpreter a virtual environment will be based on. Creating virtual environments diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst index 45d417295d06d0..44b5b818aa8233 100644 --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -616,8 +616,7 @@ the module. module.__path__ --------------- -By definition, if a module has a ``__path__`` attribute, it is a package, -regardless of its value. +By definition, if a module has a ``__path__`` attribute, it is a package. A package's ``__path__`` attribute is used during imports of its subpackages. Within the import machinery, it functions much the same as :data:`sys.path`, diff --git a/Doc/tools/static/switchers.js b/Doc/tools/static/switchers.js index 8e0c5ea0092a9f..3dea08e523bfc5 100644 --- a/Doc/tools/static/switchers.js +++ b/Doc/tools/static/switchers.js @@ -21,6 +21,7 @@ 'en': 'English', 'fr': 'French', 'ja': 'Japanese', + 'ko': 'Korean', }; function build_version_select(current_version, current_release) { diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 30ef159f8b369a..4bcdafd7335265 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -678,8 +678,8 @@ Function Annotations single: -> (return annotation assignment) :ref:`Function annotations ` are completely optional metadata -information about the types used by user-defined functions (see :pep:`484` -for more information). +information about the types used by user-defined functions (see :pep:`3107` and +:pep:`484` for more information). Annotations are stored in the :attr:`__annotations__` attribute of the function as a dictionary and have no effect on any other part of the function. Parameter diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index 584d4fd72ea82b..3f689327a0c793 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -382,7 +382,7 @@ module names". For example, the module name :mod:`A.B` designates a submodule named ``B`` in a package named ``A``. Just like the use of modules saves the authors of different modules from having to worry about each other's global variable names, the use of dotted module names saves the authors of multi-module -packages like NumPy or the Python Imaging Library from having to worry about +packages like NumPy or Pillow from having to worry about each other's module names. Suppose you want to design a collection of modules (a "package") for the uniform diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 0b822510a86ac1..3ce20fafd376a9 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -593,6 +593,14 @@ New function :func:`~os.register_at_fork` allows registering Python callbacks to be executed on a process fork. (Contributed by Antoine Pitrou in :issue:`16500`.) +Exposed the system calls *preadv*, *preadv2*, *pwritev* and *pwritev2* through +the new functions :func:`~os.preadv` and :func:`~os.pwritev`. (Contributed by +Pablo Galindo in :issue:`31368`.) + +Exposed the system call *posix_spawn* through the new function +:func:`~os.posix_spawn`. (Contributed by Pablo Galindo, Serhiy Storchaka and +Gregory P. Smith in :issue:`20104`.) + pdb --- diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 2f42a9f8ba77a1..11538e26691c18 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -111,6 +111,9 @@ Deprecated Removed ======= +* The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv`` + to help eliminate confusion as to what Python interpreter the ``pyvenv`` + script is tied to. (Contributed by Brett Cannon in :issue:`25427`.) Porting to Python 3.8 diff --git a/Include/context.h b/Include/context.h index f872dceee0ca2d..8b9f1292d75b6f 100644 --- a/Include/context.h +++ b/Include/context.h @@ -65,7 +65,7 @@ PyAPI_FUNC(PyContextToken *) PyContextVar_Set( /* Reset a variable to its previous value. - Returns 0 on sucess, -1 on error. + Returns 0 on success, -1 on error. */ PyAPI_FUNC(int) PyContextVar_Reset( PyContextVar *var, PyContextToken *token); diff --git a/Include/internal/hamt.h b/Include/internal/hamt.h index 52488d0858dfcf..29ad28b1d8706e 100644 --- a/Include/internal/hamt.h +++ b/Include/internal/hamt.h @@ -80,7 +80,7 @@ PyHamtObject * _PyHamt_Without(PyHamtObject *o, PyObject *key); /* Find "key" in the "o" collection. Return: - - -1: An error ocurred. + - -1: An error occurred. - 0: "key" wasn't found in "o". - 1: "key" is in "o"; "*val" is set to its value (a borrowed ref). */ diff --git a/Lib/_strptime.py b/Lib/_strptime.py index 1be04850acf6e9..c8f2f94e5500cf 100644 --- a/Lib/_strptime.py +++ b/Lib/_strptime.py @@ -463,7 +463,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"): z = z[:3] + z[4:] if len(z) > 5: if z[5] != ':': - msg = f"Unconsistent use of : in {found_dict['z']}" + msg = f"Inconsistent use of : in {found_dict['z']}" raise ValueError(msg) z = z[:5] + z[6:] hours = int(z[1:3]) diff --git a/Lib/cgitb.py b/Lib/cgitb.py index b29110018cd104..4f81271be3ca78 100644 --- a/Lib/cgitb.py +++ b/Lib/cgitb.py @@ -124,8 +124,9 @@ def html(einfo, context=5): args, varargs, varkw, locals = inspect.getargvalues(frame) call = '' if func != '?': - call = 'in ' + strong(func) + \ - inspect.formatargvalues(args, varargs, varkw, locals, + call = 'in ' + strong(pydoc.html.escape(func)) + if func != "": + call += inspect.formatargvalues(args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) highlight = {} @@ -207,8 +208,9 @@ def text(einfo, context=5): args, varargs, varkw, locals = inspect.getargvalues(frame) call = '' if func != '?': - call = 'in ' + func + \ - inspect.formatargvalues(args, varargs, varkw, locals, + call = 'in ' + func + if func != "": + call += inspect.formatargvalues(args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.text.repr(value)) highlight = {} @@ -282,7 +284,7 @@ def handle(self, info=None): if self.display: if plain: - doc = doc.replace('&', '&').replace('<', '<') + doc = pydoc.html.escape(doc) self.file.write('
' + doc + '
\n') else: self.file.write(doc + '\n') diff --git a/Lib/configparser.py b/Lib/configparser.py index 33dc9b9046f102..a681d3990e7261 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -846,6 +846,7 @@ def items(self, section=_UNSET, raw=False, vars=None): except KeyError: if section != self.default_section: raise NoSectionError(section) + orig_keys = list(d.keys()) # Update with the entry specific variables if vars: for key, value in vars.items(): @@ -854,7 +855,7 @@ def items(self, section=_UNSET, raw=False, vars=None): section, option, d[option], d) if raw: value_getter = lambda option: d[option] - return [(option, value_getter(option)) for option in d.keys()] + return [(option, value_getter(option)) for option in orig_keys] def popitem(self): """Remove a section from the parser and return it as diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 4a5b0583f88558..8dc2354ce28734 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -10,7 +10,7 @@ _SETUPTOOLS_VERSION = "39.0.1" -_PIP_VERSION = "9.0.3" +_PIP_VERSION = "10.0.1" _PROJECTS = [ ("setuptools", _SETUPTOOLS_VERSION), @@ -24,8 +24,8 @@ def _run_pip(args, additional_paths=None): sys.path = additional_paths + sys.path # Install the bundled software - import pip - return pip.main(args) + import pip._internal + return pip._internal.main(args) def version(): diff --git a/Lib/ensurepip/_bundled/pip-10.0.1-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-10.0.1-py2.py3-none-any.whl new file mode 100644 index 00000000000000..9837092c07bba1 Binary files /dev/null and b/Lib/ensurepip/_bundled/pip-10.0.1-py2.py3-none-any.whl differ diff --git a/Lib/ensurepip/_bundled/pip-9.0.3-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-9.0.3-py2.py3-none-any.whl deleted file mode 100644 index 5d33bba2286813..00000000000000 Binary files a/Lib/ensurepip/_bundled/pip-9.0.3-py2.py3-none-any.whl and /dev/null differ diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py index b2e995c0c47f6d..6694f5478bdadf 100644 --- a/Lib/http/cookies.py +++ b/Lib/http/cookies.py @@ -408,6 +408,8 @@ def OutputString(self, attrs=None): append("%s=%s" % (self._reserved[key], _getdate(value))) elif key == "max-age" and isinstance(value, int): append("%s=%d" % (self._reserved[key], value)) + elif key == "comment" and isinstance(value, str): + append("%s=%s" % (self._reserved[key], _quote(value))) elif key in self._flags: if value: append(str(self._reserved[key])) diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index c4aab2ee78b08f..c8b0caabd284c4 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -39,7 +39,7 @@ bpo-31860: The font sample in the settings dialog is now editable. Edits persist while IDLE remains open. Patch by Serhiy Storchake and Terry Jan Reedy. -bpo-31858: Restrict shell prompt manipulaton to the shell. +bpo-31858: Restrict shell prompt manipulation to the shell. Editor and output windows only see an empty last prompt line. This simplifies the code and fixes a minor bug when newline is inserted. Sys.ps1, if present, is read on Shell start-up, but is not set or changed. diff --git a/Lib/lib2to3/main.py b/Lib/lib2to3/main.py index 1a1df013ade3ea..d6b708848ede1a 100644 --- a/Lib/lib2to3/main.py +++ b/Lib/lib2to3/main.py @@ -80,7 +80,7 @@ def write_file(self, new_text, filename, old_text, encoding): filename += self._append_suffix if orig_filename != filename: output_dir = os.path.dirname(filename) - if not os.path.isdir(output_dir): + if not os.path.isdir(output_dir) and output_dir: os.makedirs(output_dir) self.log_message('Writing converted %s to %s.', orig_filename, filename) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index c86dd6d13457af..f25872102b8c27 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -113,7 +113,7 @@ def guess_type(self, url, strict=True): Optional `strict' argument when False adds a bunch of commonly found, but non-standard types. """ - scheme, url = urllib.parse.splittype(url) + scheme, url = urllib.parse._splittype(url) if scheme == 'data': # syntax of data URLs: # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 5332975e0a651f..7c259d2af418fe 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -161,7 +161,7 @@ def CheckInTransactionRO(self): self.cx.in_transaction = True def CheckOpenWithPathLikeObject(self): - """ Checks that we can succesfully connect to a database using an object that + """ Checks that we can successfully connect to a database using an object that is PathLike, i.e. has __fspath__(). """ self.addCleanup(unlink, TESTFN) class Path: diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 20185a9a595341..8b6bc4b23a0267 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1104,7 +1104,7 @@ def _on_queue_feeder_error(e, obj): q = SafeQueue(ctx=multiprocessing.get_context()) q.put(not_serializable_obj) - # Verify that q is still functionning correctly + # Verify that q is still functioning correctly q.put(True) self.assertTrue(q.get(timeout=1.0)) diff --git a/Lib/test/test__opcode.py b/Lib/test/test__opcode.py index 1075decc270420..2af1ee35bff0ab 100644 --- a/Lib/test/test__opcode.py +++ b/Lib/test/test__opcode.py @@ -15,6 +15,21 @@ def test_stack_effect(self): self.assertRaises(ValueError, _opcode.stack_effect, 30000) self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE']) self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0) + # All defined opcodes + for name, code in dis.opmap.items(): + with self.subTest(opname=name): + if code < dis.HAVE_ARGUMENT: + _opcode.stack_effect(code) + self.assertRaises(ValueError, _opcode.stack_effect, code, 0) + else: + _opcode.stack_effect(code, 0) + self.assertRaises(ValueError, _opcode.stack_effect, code) + # All not defined opcodes + for code in set(range(256)) - set(dis.opmap.values()): + with self.subTest(opcode=code): + self.assertRaises(ValueError, _opcode.stack_effect, code) + self.assertRaises(ValueError, _opcode.stack_effect, code, 0) + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index 397d3599312bec..4ef77716c662dd 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -1001,7 +1001,7 @@ def test_drop_close_if_unassociated(self): interpreters.channel_recv(cid) def test_drop_partially(self): - # XXX Is partial close too wierd/confusing? + # XXX Is partial close too weird/confusing? cid = interpreters.channel_create() interpreters.channel_send(cid, None) interpreters.channel_recv(cid) diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py index a87a4224f94ddc..e299ec3ec6ceb5 100644 --- a/Lib/test/test_cgitb.py +++ b/Lib/test/test_cgitb.py @@ -45,6 +45,7 @@ def test_syshook_no_logdir_default_format(self): out = out.decode(sys.getfilesystemencoding()) self.assertIn("ValueError", out) self.assertIn("Hello World", out) + self.assertIn("<module>", out) # By default we emit HTML markup. self.assertIn('

', out) self.assertIn('

', out) diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py index 4d07203b9dac28..87b811f09b6ead 100644 --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -915,8 +915,7 @@ def test_items(self): self.check_items_config([('default', ''), ('getdefault', '||'), ('key', '|value|'), - ('name', 'value'), - ('value', 'value')]) + ('name', 'value')]) def test_safe_interpolation(self): # See http://www.python.org/sf/511737 @@ -1093,8 +1092,7 @@ def test_items(self): self.check_items_config([('default', ''), ('getdefault', '|%(default)s|'), ('key', '|%(name)s|'), - ('name', '%(value)s'), - ('value', 'value')]) + ('name', '%(value)s')]) def test_set_nonstring_types(self): cf = self.newconfig() diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index 10f7cca5047346..47753e2ef03fef 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -362,7 +362,22 @@ async def bar(): pass """def foo(): async def bar(): pass\nawait a - """] + """, + """def foo(): + async for i in arange(2): + pass + """, + """def foo(): + async with resource: + pass + """, + """async with resource: + pass + """, + """async for i in arange(2): + pass + """, + ] for code in samples: with self.subTest(code=code), self.assertRaises(SyntaxError): diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index f0a428deaf0994..78c32c4c93d35c 100644 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -38,8 +38,7 @@ def delete_files(): class AnyDBMTestCase: - _dict = {'0': b'', - 'a': b'Python:', + _dict = {'a': b'Python:', 'b': b'Programming', 'c': b'the', 'd': b'way', @@ -86,12 +85,21 @@ def test_anydbm_modification(self): f = dbm.open(_fname, 'c') self._dict['g'] = f[b'g'] = b"indented" self.read_helper(f) + # setdefault() works as in the dict interface + self.assertEqual(f.setdefault(b'xxx', b'foo'), b'foo') + self.assertEqual(f[b'xxx'], b'foo') f.close() def test_anydbm_read(self): self.init_db() f = dbm.open(_fname, 'r') self.read_helper(f) + # get() works as in the dict interface + self.assertEqual(f.get(b'a'), self._dict['a']) + self.assertEqual(f.get(b'xxx', b'foo'), b'foo') + self.assertIsNone(f.get(b'xxx')) + with self.assertRaises(KeyError): + f[b'xxx'] f.close() def test_anydbm_keys(self): @@ -100,6 +108,20 @@ def test_anydbm_keys(self): keys = self.keys_helper(f) f.close() + def test_empty_value(self): + if getattr(dbm._defaultmod, 'library', None) == 'Berkeley DB': + self.skipTest("Berkeley DB doesn't distinguish the empty value " + "from the absent one") + f = dbm.open(_fname, 'c') + self.assertEqual(f.keys(), []) + f[b'empty'] = b'' + self.assertEqual(f.keys(), [b'empty']) + self.assertIn(b'empty', f) + self.assertEqual(f[b'empty'], b'') + self.assertEqual(f.get(b'empty'), b'') + self.assertEqual(f.setdefault(b'empty'), b'') + f.close() + def test_anydbm_access(self): self.init_db() f = dbm.open(_fname, 'r') diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index 652a355d990b8d..58b9d174656895 100644 --- a/Lib/test/test_dbm_dumb.py +++ b/Lib/test/test_dbm_dumb.py @@ -73,6 +73,9 @@ def test_dumbdbm_modification(self): f = dumbdbm.open(_fname, 'w') self._dict[b'g'] = f[b'g'] = b"indented" self.read_helper(f) + # setdefault() works as in the dict interface + self.assertEqual(f.setdefault(b'xxx', b'foo'), b'foo') + self.assertEqual(f[b'xxx'], b'foo') f.close() def test_dumbdbm_read(self): @@ -85,6 +88,12 @@ def test_dumbdbm_read(self): with self.assertRaisesRegex(ValueError, 'The database is opened for reading only'): del f[b'a'] + # get() works as in the dict interface + self.assertEqual(f.get(b'a'), self._dict[b'a']) + self.assertEqual(f.get(b'xxx', b'foo'), b'foo') + self.assertIsNone(f.get(b'xxx')) + with self.assertRaises(KeyError): + f[b'xxx'] f.close() def test_dumbdbm_keys(self): diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py index d96df92848063c..463d343411558c 100644 --- a/Lib/test/test_dbm_gnu.py +++ b/Lib/test/test_dbm_gnu.py @@ -32,9 +32,12 @@ def test_key_methods(self): self.assertIn(key, key_set) key_set.remove(key) key = self.g.nextkey(key) - self.assertRaises(KeyError, lambda: self.g['xxx']) # get() and setdefault() work as in the dict interface + self.assertEqual(self.g.get(b'a'), b'b') + self.assertIsNone(self.g.get(b'xxx')) self.assertEqual(self.g.get(b'xxx', b'foo'), b'foo') + with self.assertRaises(KeyError): + self.g['xxx'] self.assertEqual(self.g.setdefault(b'xxx', b'foo'), b'foo') self.assertEqual(self.g[b'xxx'], b'foo') diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py index fb7d0e8281e32d..49b88f5cccefc8 100644 --- a/Lib/test/test_dbm_ndbm.py +++ b/Lib/test/test_dbm_ndbm.py @@ -18,7 +18,7 @@ def tearDown(self): def test_keys(self): self.d = dbm.ndbm.open(self.filename, 'c') - self.assertTrue(self.d.keys() == []) + self.assertEqual(self.d.keys(), []) self.d['a'] = 'b' self.d[b'bytes'] = b'data' self.d['12345678910'] = '019237410982340912840198242' @@ -26,6 +26,28 @@ def test_keys(self): self.assertIn('a', self.d) self.assertIn(b'a', self.d) self.assertEqual(self.d[b'bytes'], b'data') + # get() and setdefault() work as in the dict interface + self.assertEqual(self.d.get(b'a'), b'b') + self.assertIsNone(self.d.get(b'xxx')) + self.assertEqual(self.d.get(b'xxx', b'foo'), b'foo') + with self.assertRaises(KeyError): + self.d['xxx'] + self.assertEqual(self.d.setdefault(b'xxx', b'foo'), b'foo') + self.assertEqual(self.d[b'xxx'], b'foo') + self.d.close() + + def test_empty_value(self): + if dbm.ndbm.library == 'Berkeley DB': + self.skipTest("Berkeley DB doesn't distinguish the empty value " + "from the absent one") + self.d = dbm.ndbm.open(self.filename, 'c') + self.assertEqual(self.d.keys(), []) + self.d['empty'] = '' + self.assertEqual(self.d.keys(), [b'empty']) + self.assertIn(b'empty', self.d) + self.assertEqual(self.d[b'empty'], b'') + self.assertEqual(self.d.get(b'empty'), b'') + self.assertEqual(self.d.setdefault(b'empty'), b'') self.d.close() def test_modes(self): diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index f926301b846610..c52cb9948782df 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -208,7 +208,7 @@ def test_pre_initialization_sys_options(self): Checks that sys.warnoptions and sys._xoptions can be set before the runtime is initialized (otherwise they won't be effective). """ - env = dict(PYTHONPATH=os.pathsep.join(sys.path)) + env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path)) out, err = self.run_embedded_interpreter( "pre_initialization_sys_options", env=env) expected_output = ( diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py index 447f883390fd73..6072c7e15e92be 100644 --- a/Lib/test/test_http_cookies.py +++ b/Lib/test/test_http_cookies.py @@ -220,6 +220,16 @@ def test_illegal_chars(self): with self.assertRaises(cookies.CookieError): C.load(rawdata) + def test_comment_quoting(self): + c = cookies.SimpleCookie() + c['foo'] = '\N{COPYRIGHT SIGN}' + self.assertEqual(str(c['foo']), 'Set-Cookie: foo="\\251"') + c['foo']['comment'] = 'comment \N{COPYRIGHT SIGN}' + self.assertEqual( + str(c['foo']), + 'Set-Cookie: foo="\\251"; Comment="comment \\251"' + ) + class MorselTests(unittest.TestCase): """Tests for the Morsel object.""" diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 2f1b21978099fb..274e26061a1991 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -322,21 +322,19 @@ def test_position(self): # An absolutely minimal test of position information. Better # tests would be a big project. code = "def f(x):\n return x + 1" - st1 = parser.suite(code) - st2 = st1.totuple(line_info=1, col_info=1) + st = parser.suite(code) def walk(tree): node_type = tree[0] next = tree[1] - if isinstance(next, tuple): + if isinstance(next, (tuple, list)): for elt in tree[1:]: for x in walk(elt): yield x else: yield tree - terminals = list(walk(st2)) - self.assertEqual([ + expected = [ (1, 'def', 1, 0), (1, 'f', 1, 4), (7, '(', 1, 5), @@ -352,8 +350,25 @@ def walk(tree): (4, '', 2, 16), (6, '', 2, -1), (4, '', 2, -1), - (0, '', 2, -1)], - terminals) + (0, '', 2, -1), + ] + + self.assertEqual(list(walk(st.totuple(line_info=True, col_info=True))), + expected) + self.assertEqual(list(walk(st.totuple())), + [(t, n) for t, n, l, c in expected]) + self.assertEqual(list(walk(st.totuple(line_info=True))), + [(t, n, l) for t, n, l, c in expected]) + self.assertEqual(list(walk(st.totuple(col_info=True))), + [(t, n, c) for t, n, l, c in expected]) + self.assertEqual(list(walk(st.tolist(line_info=True, col_info=True))), + [list(x) for x in expected]) + self.assertEqual(list(walk(parser.st2tuple(st, line_info=True, + col_info=True))), + expected) + self.assertEqual(list(walk(parser.st2list(st, line_info=True, + col_info=True))), + [list(x) for x in expected]) def test_extended_unpacking(self): self.check_suite("*a = y") diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index bff1dc2d0638c2..44501d922ad348 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -5948,7 +5948,7 @@ def test_sendmsg_afalg_args(self): @unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") class TestMSWindowsTCPFlags(unittest.TestCase): knownTCPFlags = { - # avaliable since long time ago + # available since long time ago 'TCP_MAXSEG', 'TCP_NODELAY', # available starting with Windows 10 1607 diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index af71008bec537e..de2773f6aa2916 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -363,7 +363,7 @@ def test_bad_offset(self): _strptime._strptime("-01:30:30:123456", "%z") with self.assertRaises(ValueError) as err: _strptime._strptime("-01:3030", "%z") - self.assertEqual("Unconsistent use of : in -01:3030", str(err.exception)) + self.assertEqual("Inconsistent use of : in -01:3030", str(err.exception)) def test_timezone(self): # Test timezone directives. diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 6933b41353bd56..336ae447a8de5e 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -852,6 +852,9 @@ def check(tracebacklimit, expected): check(-1<<1000, [traceback[-1]]) check(None, traceback) + def test_no_duplicates_in_meta_path(self): + self.assertEqual(len(sys.meta_path), len(set(sys.meta_path))) + @test.support.cpython_only class SizeofTest(unittest.TestCase): diff --git a/Lib/test/test_tools/test_i18n.py b/Lib/test/test_tools/test_i18n.py index 56a273429898ab..8b2b90d6142bb4 100644 --- a/Lib/test/test_tools/test_i18n.py +++ b/Lib/test/test_tools/test_i18n.py @@ -3,7 +3,7 @@ import os import sys import unittest -import textwrap +from textwrap import dedent from test.support.script_helper import assert_python_ok from test.test_tools import skip_if_missing, toolsdir @@ -109,9 +109,68 @@ def test_POT_Creation_Date(self): # This will raise if the date format does not exactly match. datetime.strptime(creationDate, '%Y-%m-%d %H:%M%z') + def test_funcdocstring(self): + for doc in ('"""doc"""', "r'''doc'''", "R'doc'", 'u"doc"'): + with self.subTest(doc): + msgids = self.extract_docstrings_from_str(dedent('''\ + def foo(bar): + %s + ''' % doc)) + self.assertIn('doc', msgids) + + def test_funcdocstring_bytes(self): + msgids = self.extract_docstrings_from_str(dedent('''\ + def foo(bar): + b"""doc""" + ''')) + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + + def test_funcdocstring_fstring(self): + msgids = self.extract_docstrings_from_str(dedent('''\ + def foo(bar): + f"""doc""" + ''')) + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + + def test_classdocstring(self): + for doc in ('"""doc"""', "r'''doc'''", "R'doc'", 'u"doc"'): + with self.subTest(doc): + msgids = self.extract_docstrings_from_str(dedent('''\ + class C: + %s + ''' % doc)) + self.assertIn('doc', msgids) + + def test_classdocstring_bytes(self): + msgids = self.extract_docstrings_from_str(dedent('''\ + class C: + b"""doc""" + ''')) + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + + def test_classdocstring_fstring(self): + msgids = self.extract_docstrings_from_str(dedent('''\ + class C: + f"""doc""" + ''')) + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + + def test_msgid(self): + msgids = self.extract_docstrings_from_str( + '''_("""doc""" r'str' u"ing")''') + self.assertIn('docstring', msgids) + + def test_msgid_bytes(self): + msgids = self.extract_docstrings_from_str('_(b"""doc""")') + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + + def test_msgid_fstring(self): + msgids = self.extract_docstrings_from_str('_(f"""doc""")') + self.assertFalse([msgid for msgid in msgids if 'doc' in msgid]) + def test_funcdocstring_annotated_args(self): """ Test docstrings for functions with annotated args """ - msgids = self.extract_docstrings_from_str(textwrap.dedent('''\ + msgids = self.extract_docstrings_from_str(dedent('''\ def foo(bar: str): """doc""" ''')) @@ -119,7 +178,7 @@ def foo(bar: str): def test_funcdocstring_annotated_return(self): """ Test docstrings for functions with annotated return type """ - msgids = self.extract_docstrings_from_str(textwrap.dedent('''\ + msgids = self.extract_docstrings_from_str(dedent('''\ def foo(bar) -> str: """doc""" ''')) @@ -127,7 +186,7 @@ def foo(bar) -> str: def test_funcdocstring_defvalue_args(self): """ Test docstring for functions with default arg values """ - msgids = self.extract_docstrings_from_str(textwrap.dedent('''\ + msgids = self.extract_docstrings_from_str(dedent('''\ def foo(bar=()): """doc""" ''')) @@ -137,7 +196,7 @@ def test_funcdocstring_multiple_funcs(self): """ Test docstring extraction for multiple functions combining annotated args, annotated return types and default arg values """ - msgids = self.extract_docstrings_from_str(textwrap.dedent('''\ + msgids = self.extract_docstrings_from_str(dedent('''\ def foo1(bar: tuple=()) -> str: """doc1""" @@ -155,7 +214,7 @@ def test_classdocstring_early_colon(self): """ Test docstring extraction for a class with colons occuring within the parentheses. """ - msgids = self.extract_docstrings_from_str(textwrap.dedent('''\ + msgids = self.extract_docstrings_from_str(dedent('''\ class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)): """doc""" ''')) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 9d512179283366..25c3762d813020 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -1,5 +1,6 @@ import unittest import urllib.parse +import warnings RFC1808_BASE = "http://a/b/c/d;p?q#f" RFC2396_BASE = "http://a/b/c/d;p?q" @@ -1129,7 +1130,7 @@ def test_splitvalue(self): def test_to_bytes(self): result = urllib.parse.to_bytes('http://www.python.org') self.assertEqual(result, 'http://www.python.org') - self.assertRaises(UnicodeError, urllib.parse.to_bytes, + self.assertRaises(UnicodeError, urllib.parse._to_bytes, 'http://www.python.org/medi\u00e6val') def test_unwrap(self): @@ -1137,5 +1138,90 @@ def test_unwrap(self): self.assertEqual(url, 'type://host/path') +class DeprecationTest(unittest.TestCase): + + def test_splittype_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splittype('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splittype() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splithost_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splithost('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splithost() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splituser_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splituser('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splituser() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitpasswd_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitpasswd('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitpasswd() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitport_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitport('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitport() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitnport_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitnport('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitnport() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitquery_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitquery('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitquery() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splittag_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splittag('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splittag() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitattr_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitattr('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitattr() is deprecated as of 3.8, ' + 'use urllib.parse.urlparse() instead') + + def test_splitvalue_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.splitvalue('') + self.assertEqual(str(cm.warning), + 'urllib.parse.splitvalue() is deprecated as of 3.8, ' + 'use urllib.parse.parse_qsl() instead') + + def test_to_bytes_deprecation(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.to_bytes('') + self.assertEqual(str(cm.warning), + 'urllib.parse.to_bytes() is deprecated as of 3.8') + + def test_unwrap(self): + with self.assertWarns(DeprecationWarning) as cm: + urllib.parse.unwrap('') + self.assertEqual(str(cm.warning), + 'urllib.parse.unwrap() is deprecated as of 3.8') + + if __name__ == "__main__": unittest.main() diff --git a/Lib/tokenize.py b/Lib/tokenize.py index 6528b900612863..40e6a8b9297b24 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -28,7 +28,6 @@ from codecs import lookup, BOM_UTF8 import collections from io import TextIOWrapper -from itertools import chain import itertools as _itertools import re import sys @@ -278,7 +277,7 @@ def compat(self, token, iterable): startline = token[0] in (NEWLINE, NL) prevstring = False - for tok in chain([token], iterable): + for tok in _itertools.chain([token], iterable): toknum, tokval = tok[:2] if toknum == ENCODING: self.encoding = tokval @@ -475,13 +474,10 @@ def tokenize(readline): The first token sequence will always be an ENCODING token which tells you which encoding was used to decode the bytes stream. """ - # This import is here to avoid problems when the itertools module is not - # built yet and tokenize is imported. - from itertools import chain, repeat encoding, consumed = detect_encoding(readline) - rl_gen = iter(readline, b"") - empty = repeat(b"") - return _tokenize(chain(consumed, rl_gen, empty).__next__, encoding) + empty = _itertools.repeat(b"") + rl_gen = _itertools.chain(consumed, iter(readline, b""), empty) + return _tokenize(rl_gen.__next__, encoding) def _tokenize(readline, encoding): @@ -496,7 +492,7 @@ def _tokenize(readline, encoding): # BOM will already have been stripped. encoding = "utf-8" yield TokenInfo(ENCODING, encoding, (0, 0), (0, 0), '') - while True: # loop over lines in stream + while True: # loop over lines in stream try: line = readline() except StopIteration: @@ -581,7 +577,7 @@ def _tokenize(readline, encoding): continue token, initial = line[start:end], line[start] - if (initial in numchars or # ordinary number + if (initial in numchars or # ordinary number (initial == '.' and token != '.' and token != '...')): yield TokenInfo(NUMBER, token, spos, epos, line) elif initial in '\r\n': @@ -667,7 +663,8 @@ def main(): # Helper error handling routines def perror(message): - print(message, file=sys.stderr) + sys.stderr.write(message) + sys.stderr.write('\n') def error(message, filename=None, location=None): if location: diff --git a/Lib/typing.py b/Lib/typing.py index d45502ffee48be..83296073b9147e 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -732,7 +732,7 @@ def __mro_entries__(self, bases): return (self.__origin__,) def __getattr__(self, attr): - # We are carefull for copy and pickle. + # We are careful for copy and pickle. # Also for simplicity we just don't relay all dunder names if '__origin__' in self.__dict__ and not _is_dunder(attr): return getattr(self.__origin__, attr) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 3f8cfe5300c024..f21b8eb49cca22 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -30,6 +30,7 @@ import re import sys import collections +import warnings __all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag", "urlsplit", "urlunsplit", "urlencode", "parse_qs", @@ -288,7 +289,7 @@ def _hostinfo(self): """ _ParseResultBase.__doc__ = """ -ParseResult(scheme, netloc, path, params, query, fragment) +ParseResult(scheme, netloc, path, params, query, fragment) A 6-tuple that contains components of a parsed URL. """ @@ -913,7 +914,14 @@ def urlencode(query, doseq=False, safe='', encoding=None, errors=None, l.append(k + '=' + elt) return '&'.join(l) + def to_bytes(url): + warnings.warn("urllib.parse.to_bytes() is deprecated as of 3.8", + DeprecationWarning, stacklevel=2) + return _to_bytes(url) + + +def _to_bytes(url): """to_bytes(u"URL") --> 'URL'.""" # Most URL schemes require ASCII. If that changes, the conversion # can be relaxed. @@ -926,7 +934,14 @@ def to_bytes(url): " contains non-ASCII characters") return url + def unwrap(url): + warnings.warn("urllib.parse.unwrap() is deprecated as of 3.8", + DeprecationWarning, stacklevel=2) + return _unwrap(url) + + +def _unwrap(url): """unwrap('') --> 'type://host/path'.""" url = str(url).strip() if url[:1] == '<' and url[-1:] == '>': @@ -934,8 +949,16 @@ def unwrap(url): if url[:4] == 'URL:': url = url[4:].strip() return url -_typeprog = None + def splittype(url): + warnings.warn("urllib.parse.splittype() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splittype(url) + + +_typeprog = None +def _splittype(url): """splittype('type:opaquestring') --> 'type', 'opaquestring'.""" global _typeprog if _typeprog is None: @@ -947,8 +970,16 @@ def splittype(url): return scheme.lower(), data return None, url -_hostprog = None + def splithost(url): + warnings.warn("urllib.parse.splithost() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splithost(url) + + +_hostprog = None +def _splithost(url): """splithost('//host[:port]/path') --> 'host[:port]', '/path'.""" global _hostprog if _hostprog is None: @@ -962,19 +993,43 @@ def splithost(url): return host_port, path return None, url + def splituser(host): + warnings.warn("urllib.parse.splituser() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splituser(host) + + +def _splituser(host): """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.""" user, delim, host = host.rpartition('@') return (user if delim else None), host + def splitpasswd(user): + warnings.warn("urllib.parse.splitpasswd() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splitpasswd(user) + + +def _splitpasswd(user): """splitpasswd('user:passwd') -> 'user', 'passwd'.""" user, delim, passwd = user.partition(':') return user, (passwd if delim else None) + +def splitport(host): + warnings.warn("urllib.parse.splitport() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splitport(host) + + # splittag('/path#tag') --> '/path', 'tag' _portprog = None -def splitport(host): +def _splitport(host): """splitport('host:port') --> 'host', 'port'.""" global _portprog if _portprog is None: @@ -987,7 +1042,15 @@ def splitport(host): return host, port return host, None + def splitnport(host, defport=-1): + warnings.warn("urllib.parse.splitnport() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splitnport(host, defport) + + +def _splitnport(host, defport=-1): """Split host and port, returning numeric port. Return given default port if no ':' found; defaults to -1. Return numerical port if a valid number are found after ':'. @@ -1003,27 +1066,59 @@ def splitnport(host, defport=-1): return host, nport return host, defport + def splitquery(url): + warnings.warn("urllib.parse.splitquery() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splitquery(url) + + +def _splitquery(url): """splitquery('/path?query') --> '/path', 'query'.""" path, delim, query = url.rpartition('?') if delim: return path, query return url, None + def splittag(url): + warnings.warn("urllib.parse.splittag() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splittag(url) + + +def _splittag(url): """splittag('/path#tag') --> '/path', 'tag'.""" path, delim, tag = url.rpartition('#') if delim: return path, tag return url, None + def splitattr(url): + warnings.warn("urllib.parse.splitattr() is deprecated as of 3.8, " + "use urllib.parse.urlparse() instead", + DeprecationWarning, stacklevel=2) + return _splitattr(url) + + +def _splitattr(url): """splitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].""" words = url.split(';') return words[0], words[1:] + def splitvalue(attr): + warnings.warn("urllib.parse.splitvalue() is deprecated as of 3.8, " + "use urllib.parse.parse_qsl() instead", + DeprecationWarning, stacklevel=2) + return _splitvalue(attr) + + +def _splitvalue(attr): """splitvalue('attr=value') --> 'attr', 'value'.""" attr, delim, value = attr.partition('=') return attr, (value if delim else None) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 5b962f7dc20b99..9d50b688a3a5b1 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -101,9 +101,9 @@ from urllib.error import URLError, HTTPError, ContentTooShortError from urllib.parse import ( - urlparse, urlsplit, urljoin, unwrap, quote, unquote, - splittype, splithost, splitport, splituser, splitpasswd, - splitattr, splitquery, splitvalue, splittag, to_bytes, + urlparse, urlsplit, urljoin, _unwrap, quote, unquote, + _splittype, _splithost, _splitport, _splituser, _splitpasswd, + _splitattr, _splitquery, _splitvalue, _splittag, _to_bytes, unquote_to_bytes, urlunparse) from urllib.response import addinfourl, addclosehook @@ -242,7 +242,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None): Returns a tuple containing the path to the newly created data file as well as the resulting HTTPMessage object. """ - url_type, path = splittype(url) + url_type, path = _splittype(url) with contextlib.closing(urlopen(url, data)) as fp: headers = fp.info() @@ -349,8 +349,8 @@ def full_url(self): @full_url.setter def full_url(self, url): # unwrap('') --> 'type://host/path' - self._full_url = unwrap(url) - self._full_url, self.fragment = splittag(self._full_url) + self._full_url = _unwrap(url) + self._full_url, self.fragment = _splittag(self._full_url) self._parse() @full_url.deleter @@ -378,10 +378,10 @@ def data(self): self.data = None def _parse(self): - self.type, rest = splittype(self._full_url) + self.type, rest = _splittype(self._full_url) if self.type is None: raise ValueError("unknown url type: %r" % self.full_url) - self.host, self.selector = splithost(rest) + self.host, self.selector = _splithost(rest) if self.host: self.host = unquote(self.host) @@ -768,7 +768,7 @@ def _parse_proxy(proxy): According to RFC 3986, having an authority component means the URL must have two slashes after the scheme. """ - scheme, r_scheme = splittype(proxy) + scheme, r_scheme = _splittype(proxy) if not r_scheme.startswith("/"): # authority scheme = None @@ -783,9 +783,9 @@ def _parse_proxy(proxy): if end == -1: end = None authority = r_scheme[2:end] - userinfo, hostport = splituser(authority) + userinfo, hostport = _splituser(authority) if userinfo is not None: - user, password = splitpasswd(userinfo) + user, password = _splitpasswd(userinfo) else: user = password = None return scheme, user, password, hostport @@ -872,7 +872,7 @@ def reduce_uri(self, uri, default_port=True): scheme = None authority = uri path = '/' - host, port = splitport(authority) + host, port = _splitport(authority) if default_port and port is None and scheme is not None: dport = {"http": 80, "https": 443, @@ -1261,8 +1261,8 @@ def do_request_(self, request): sel_host = host if request.has_proxy(): - scheme, sel = splittype(request.selector) - sel_host, sel_path = splithost(sel) + scheme, sel = _splittype(request.selector) + sel_host, sel_path = _splithost(sel) if not request.has_header('Host'): request.add_unredirected_header('Host', sel_host) for name, value in self.parent.addheaders: @@ -1478,7 +1478,7 @@ def open_local_file(self, req): 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified)) if host: - host, port = splitport(host) + host, port = _splitport(host) if not host or \ (not port and _safe_gethostbyname(host) in self.get_names()): if host: @@ -1503,16 +1503,16 @@ def ftp_open(self, req): host = req.host if not host: raise URLError('ftp error: no host given') - host, port = splitport(host) + host, port = _splitport(host) if port is None: port = ftplib.FTP_PORT else: port = int(port) # username/password handling - user, host = splituser(host) + user, host = _splituser(host) if user: - user, passwd = splitpasswd(user) + user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) @@ -1523,7 +1523,7 @@ def ftp_open(self, req): host = socket.gethostbyname(host) except OSError as msg: raise URLError(msg) - path, attrs = splitattr(req.selector) + path, attrs = _splitattr(req.selector) dirs = path.split('/') dirs = list(map(unquote, dirs)) dirs, file = dirs[:-1], dirs[-1] @@ -1533,7 +1533,7 @@ def ftp_open(self, req): fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) type = file and 'I' or 'D' for attr in attrs: - attr, value = splitvalue(attr) + attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() @@ -1727,19 +1727,19 @@ def addheader(self, *args): # External interface def open(self, fullurl, data=None): """Use URLopener().open(file) instead of open(file, 'r').""" - fullurl = unwrap(to_bytes(fullurl)) + fullurl = _unwrap(_to_bytes(fullurl)) fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|") if self.tempcache and fullurl in self.tempcache: filename, headers = self.tempcache[fullurl] fp = open(filename, 'rb') return addinfourl(fp, headers, fullurl) - urltype, url = splittype(fullurl) + urltype, url = _splittype(fullurl) if not urltype: urltype = 'file' if urltype in self.proxies: proxy = self.proxies[urltype] - urltype, proxyhost = splittype(proxy) - host, selector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + host, selector = _splithost(proxyhost) url = (host, fullurl) # Signal special case to open_*() else: proxy = None @@ -1763,22 +1763,22 @@ def open(self, fullurl, data=None): def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) + type, url = _splittype(fullurl) raise OSError('url error', 'unknown url type', type) def open_unknown_proxy(self, proxy, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) + type, url = _splittype(fullurl) raise OSError('url error', 'invalid proxy for %s' % type, proxy) # External interface def retrieve(self, url, filename=None, reporthook=None, data=None): """retrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.""" - url = unwrap(to_bytes(url)) + url = _unwrap(_to_bytes(url)) if self.tempcache and url in self.tempcache: return self.tempcache[url] - type, url1 = splittype(url) + type, url1 = _splittype(url) if filename is None and (not type or type == 'file'): try: fp = self.open_local_file(url1) @@ -1853,25 +1853,25 @@ def _open_generic_http(self, connection_factory, url, data): user_passwd = None proxy_passwd= None if isinstance(url, str): - host, selector = splithost(url) + host, selector = _splithost(url) if host: - user_passwd, host = splituser(host) + user_passwd, host = _splituser(host) host = unquote(host) realhost = host else: host, selector = url # check whether the proxy contains authorization information - proxy_passwd, host = splituser(host) + proxy_passwd, host = _splituser(host) # now we proceed with the url we want to obtain - urltype, rest = splittype(selector) + urltype, rest = _splittype(selector) url = rest user_passwd = None if urltype.lower() != 'http': realhost = None else: - realhost, rest = splithost(rest) + realhost, rest = _splithost(rest) if realhost: - user_passwd, realhost = splituser(realhost) + user_passwd, realhost = _splituser(realhost) if user_passwd: selector = "%s://%s%s" % (urltype, realhost, rest) if proxy_bypass(realhost): @@ -1977,7 +1977,7 @@ def open_local_file(self, url): """Use local file.""" import email.utils import mimetypes - host, file = splithost(url) + host, file = _splithost(url) localname = url2pathname(file) try: stats = os.stat(localname) @@ -1994,7 +1994,7 @@ def open_local_file(self, url): if file[:1] == '/': urlfile = 'file://' + file return addinfourl(open(localname, 'rb'), headers, urlfile) - host, port = splitport(host) + host, port = _splitport(host) if (not port and socket.gethostbyname(host) in ((localhost(),) + thishost())): urlfile = file @@ -2010,11 +2010,11 @@ def open_ftp(self, url): if not isinstance(url, str): raise URLError('ftp error: proxy support for ftp protocol currently not implemented') import mimetypes - host, path = splithost(url) + host, path = _splithost(url) if not host: raise URLError('ftp error: no host given') - host, port = splitport(host) - user, host = splituser(host) - if user: user, passwd = splitpasswd(user) + host, port = _splitport(host) + user, host = _splituser(host) + if user: user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) user = unquote(user or '') @@ -2025,7 +2025,7 @@ def open_ftp(self, url): port = ftplib.FTP_PORT else: port = int(port) - path, attrs = splitattr(path) + path, attrs = _splitattr(path) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] @@ -2047,7 +2047,7 @@ def open_ftp(self, url): if not file: type = 'D' else: type = 'I' for attr in attrs: - attr, value = splitvalue(attr) + attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() @@ -2230,11 +2230,11 @@ def http_error_407(self, url, fp, errcode, errmsg, headers, data=None, return getattr(self,name)(url, realm, data) def retry_proxy_http_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) newurl = 'http://' + host + selector proxy = self.proxies['http'] - urltype, proxyhost = splittype(proxy) - proxyhost, proxyselector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) @@ -2248,11 +2248,11 @@ def retry_proxy_http_basic_auth(self, url, realm, data=None): return self.open(newurl, data) def retry_proxy_https_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) newurl = 'https://' + host + selector proxy = self.proxies['https'] - urltype, proxyhost = splittype(proxy) - proxyhost, proxyselector = splithost(proxyhost) + urltype, proxyhost = _splittype(proxy) + proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) @@ -2266,7 +2266,7 @@ def retry_proxy_https_basic_auth(self, url, realm, data=None): return self.open(newurl, data) def retry_http_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) @@ -2280,7 +2280,7 @@ def retry_http_basic_auth(self, url, realm, data=None): return self.open(newurl, data) def retry_https_basic_auth(self, url, realm, data=None): - host, selector = splithost(url) + host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) @@ -2502,7 +2502,7 @@ def proxy_bypass_environment(host, proxies=None): if no_proxy == '*': return 1 # strip port off host - hostonly, port = splitport(host) + hostonly, port = _splitport(host) # check if the host ends with any of the DNS suffixes no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] for name in no_proxy_list: @@ -2533,7 +2533,7 @@ def _proxy_bypass_macosx_sysconf(host, proxy_settings): """ from fnmatch import fnmatch - hostonly, port = splitport(host) + hostonly, port = _splitport(host) def ip2num(ipAddr): parts = ipAddr.split('.') @@ -2687,7 +2687,7 @@ def proxy_bypass_registry(host): if not proxyEnable or not proxyOverride: return 0 # try to make a host list from name and IP address. - rawHost, port = splitport(host) + rawHost, port = _splitport(host) host = [rawHost] try: addr = socket.gethostbyname(rawHost) diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 1e8bb5f1bb965d..ddab76ffbe8309 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1214,7 +1214,7 @@ def get_host_info(self, host): if isinstance(host, tuple): host, x509 = host - auth, host = urllib.parse.splituser(host) + auth, host = urllib.parse._splituser(host) if auth: auth = urllib.parse.unquote_to_bytes(auth) @@ -1413,10 +1413,10 @@ def __init__(self, uri, transport=None, encoding=None, verbose=False, # establish a "logical" server connection # get the url - type, uri = urllib.parse.splittype(uri) + type, uri = urllib.parse._splittype(uri) if type not in ("http", "https"): raise OSError("unsupported XML-RPC protocol") - self.__host, self.__handler = urllib.parse.splithost(uri) + self.__host, self.__handler = urllib.parse._splithost(uri) if not self.__handler: self.__handler = "/RPC2" diff --git a/Mac/Makefile.in b/Mac/Makefile.in index 95fd4a2722d51a..0b32673323a0dc 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -67,7 +67,6 @@ installunixtools: pydoc3 \ python3 \ python3-config \ - pyvenv \ ; \ do \ rm -f $${fn} ; \ @@ -118,7 +117,6 @@ altinstallunixtools: pydoc$(VERSION) \ python$(VERSION) \ python$(LDVERSION)-config \ - pyvenv-$(VERSION) \ ; \ do \ rm -f $${fn} ;\ diff --git a/Makefile.pre.in b/Makefile.pre.in index 916f03091a00bc..a363f77e3782ba 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -106,7 +106,8 @@ ARFLAGS= @ARFLAGS@ # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files -PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE +PY_STDMODULE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) +PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE # Strict or non-strict aliasing flags used to compile dtoa.c, see above CFLAGS_ALIASING=@CFLAGS_ALIASING@ @@ -1216,8 +1217,6 @@ bininstall: altbininstall (cd $(DESTDIR)$(BINDIR); $(LN) -s pydoc$(VERSION) pydoc3) -rm -f $(DESTDIR)$(BINDIR)/2to3 (cd $(DESTDIR)$(BINDIR); $(LN) -s 2to3-$(VERSION) 2to3) - -rm -f $(DESTDIR)$(BINDIR)/pyvenv - (cd $(DESTDIR)$(BINDIR); $(LN) -s pyvenv-$(VERSION) pyvenv) if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \ rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \ (cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \ diff --git a/Misc/ACKS b/Misc/ACKS index 5efe37fb0a22d7..3b6774219f6c6c 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -158,6 +158,7 @@ Mike Bland Martin Bless Pablo Bleyer Erik van Blokland +Stéphane Blondon Eric Blossom Sergey Bobrov Finn Bock @@ -182,6 +183,7 @@ Thierry Bousch Sebastian Boving Michal Bozon Jeff Bradberry +Chris Bradbury Aaron Brancotti Monty Brandenberg Georg Brandl diff --git a/Misc/NEWS.d/next/Build/2018-03-08-20-25-29.bpo-33012.k9Fe1q.rst b/Misc/NEWS.d/next/Build/2018-03-08-20-25-29.bpo-33012.k9Fe1q.rst new file mode 100644 index 00000000000000..474053348fcc9a --- /dev/null +++ b/Misc/NEWS.d/next/Build/2018-03-08-20-25-29.bpo-33012.k9Fe1q.rst @@ -0,0 +1,5 @@ +gcc 8 has added a new warning heuristic to detect invalid function casts and +a stock python build seems to hit that warning quite often. The most common +is the cast of a METH_NOARGS function (that uses just one argument) to a +PyCFunction. Fix this by adding a dummy argument to all functions that +implement METH_NOARGS. diff --git a/Misc/NEWS.d/next/Build/2018-04-17-00-38-19.bpo-32232.o7G_UO.rst b/Misc/NEWS.d/next/Build/2018-04-17-00-38-19.bpo-32232.o7G_UO.rst new file mode 100644 index 00000000000000..fea0b60fcedd9b --- /dev/null +++ b/Misc/NEWS.d/next/Build/2018-04-17-00-38-19.bpo-32232.o7G_UO.rst @@ -0,0 +1,3 @@ +By default, modules configured in `Modules/Setup` are no longer built with +`-DPy_BUILD_CORE`. Instead, modules that specifically need that preprocessor +definition include it in their individual entries. diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-04-19-08-30-07.bpo-33312.mDe2iL.rst b/Misc/NEWS.d/next/Core and Builtins/2018-04-19-08-30-07.bpo-33312.mDe2iL.rst new file mode 100644 index 00000000000000..40b51b902c9f70 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-04-19-08-30-07.bpo-33312.mDe2iL.rst @@ -0,0 +1,3 @@ +Fixed clang ubsan (undefined behavior sanitizer) warnings in dictobject.c by +adjusting how the internal struct _dictkeysobject shared keys structure is +declared. diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst b/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst new file mode 100644 index 00000000000000..66b98cdf51cfcf --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-04-24-22-31-04.bpo-33128.g2yLuf.rst @@ -0,0 +1,2 @@ +Fix a bug that causes PathFinder to appear twice on sys.meta_path. Patch by +Pablo Galindo Salgado. diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-04-26-22-48-28.bpo-33363.8RCnN2.rst b/Misc/NEWS.d/next/Core and Builtins/2018-04-26-22-48-28.bpo-33363.8RCnN2.rst new file mode 100644 index 00000000000000..ad8d24895343b5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-04-26-22-48-28.bpo-33363.8RCnN2.rst @@ -0,0 +1,2 @@ +Raise a SyntaxError for ``async with`` and ``async for`` statements outside +of async functions. diff --git a/Misc/NEWS.d/next/Documentation/2018-04-20-14-09-36.bpo-33276.rA1z_3.rst b/Misc/NEWS.d/next/Documentation/2018-04-20-14-09-36.bpo-33276.rA1z_3.rst new file mode 100644 index 00000000000000..0da58a0ce4c896 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2018-04-20-14-09-36.bpo-33276.rA1z_3.rst @@ -0,0 +1 @@ +Clarify that the ``__path__`` attribute on modules cannot be just any value. diff --git a/Misc/NEWS.d/next/Documentation/2018-04-29-04-02-18.bpo-33378.-anAHN.rst b/Misc/NEWS.d/next/Documentation/2018-04-29-04-02-18.bpo-33378.-anAHN.rst new file mode 100644 index 00000000000000..43214d10b7c569 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2018-04-29-04-02-18.bpo-33378.-anAHN.rst @@ -0,0 +1 @@ +Add Korean language switcher for https://docs.python.org/3/ diff --git a/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst new file mode 100644 index 00000000000000..a0605c04b4deee --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst @@ -0,0 +1 @@ +Fix display of ```` call in the html produced by ``cgitb.html()``. Patch by Stéphane Blondon. diff --git a/Misc/NEWS.d/next/Library/2018-04-18-19-12-25.bpo-33308.fW75xi.rst b/Misc/NEWS.d/next/Library/2018-04-18-19-12-25.bpo-33308.fW75xi.rst new file mode 100644 index 00000000000000..586004a3c6c956 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-18-19-12-25.bpo-33308.fW75xi.rst @@ -0,0 +1,2 @@ +Fixed a crash in the :mod:`parser` module when converting an ST object to a +tree of tuples or lists with ``line_info=False`` and ``col_info=True``. diff --git a/Misc/NEWS.d/next/Library/2018-04-18-20-48-16.bpo-33311.47M7I6.rst b/Misc/NEWS.d/next/Library/2018-04-18-20-48-16.bpo-33311.47M7I6.rst new file mode 100644 index 00000000000000..3917f2223419c3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-18-20-48-16.bpo-33311.47M7I6.rst @@ -0,0 +1,2 @@ +Traceback displayed by cgitb as text or html does not display parentheses if +the current call in directly in the module diff --git a/Misc/NEWS.d/next/Library/2018-04-20-10-43-17.bpo-33131.L2E977.rst b/Misc/NEWS.d/next/Library/2018-04-20-10-43-17.bpo-33131.L2E977.rst new file mode 100644 index 00000000000000..875c6ac5f74237 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-20-10-43-17.bpo-33131.L2E977.rst @@ -0,0 +1 @@ +Upgrade bundled version of pip to 10.0.1. diff --git a/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst b/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst new file mode 100644 index 00000000000000..3af6c27cf21d49 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-21-00-24-08.bpo-991266.h93TP_.rst @@ -0,0 +1 @@ +Fix quoting of the ``Comment`` attribute of :class:`http.cookies.SimpleCookie`. diff --git a/Misc/NEWS.d/next/Library/2018-04-22-20-13-21.bpo-33334.19UMOC.rst b/Misc/NEWS.d/next/Library/2018-04-22-20-13-21.bpo-33334.19UMOC.rst new file mode 100644 index 00000000000000..1df274091863e3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-22-20-13-21.bpo-33334.19UMOC.rst @@ -0,0 +1,2 @@ +:func:`dis.stack_effect` now supports all defined opcodes including NOP and +EXTENDED_ARG. diff --git a/Misc/NEWS.d/next/Library/2018-04-23-13-21-39.bpo-33329.lQ-Eod.rst b/Misc/NEWS.d/next/Library/2018-04-23-13-21-39.bpo-33329.lQ-Eod.rst new file mode 100644 index 00000000000000..d1a4e56d04b947 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-23-13-21-39.bpo-33329.lQ-Eod.rst @@ -0,0 +1 @@ +Fix multiprocessing regression on newer glibcs diff --git a/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst b/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst new file mode 100644 index 00000000000000..fc6861f0d368ec --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst @@ -0,0 +1,2 @@ +`ConfigParser.items()` was fixed so that key-value pairs passed in via `vars` +are not included in the resulting output. diff --git a/Misc/NEWS.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst b/Misc/NEWS.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst new file mode 100644 index 00000000000000..8962d8229264d1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-25-14-05-21.bpo-27485.nclVSU.rst @@ -0,0 +1 @@ +Rename and deprecate undocumented functions in :func:`urllib.parse`. diff --git a/Misc/NEWS.d/next/Library/2018-04-29-11-15-38.bpo-33383.g32YWn.rst b/Misc/NEWS.d/next/Library/2018-04-29-11-15-38.bpo-33383.g32YWn.rst new file mode 100644 index 00000000000000..7b65baac97bf6e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-29-11-15-38.bpo-33383.g32YWn.rst @@ -0,0 +1,2 @@ +Fixed crash in the get() method of the :mod:`dbm.ndbm` database object when +it is called with a single argument. diff --git a/Misc/NEWS.d/next/Tests/2018-04-27-11-46-35.bpo-33358._OcR59.rst b/Misc/NEWS.d/next/Tests/2018-04-27-11-46-35.bpo-33358._OcR59.rst new file mode 100644 index 00000000000000..89406e994a9193 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-04-27-11-46-35.bpo-33358._OcR59.rst @@ -0,0 +1,2 @@ +Fix ``test_embed.test_pre_initialization_sys_options()`` when the interpreter +is built with ``--enable-shared``. diff --git a/Misc/NEWS.d/next/Tools-Demos/2017-09-26-10-11-21.bpo-31583.TM90_H.rst b/Misc/NEWS.d/next/Tools-Demos/2017-09-26-10-11-21.bpo-31583.TM90_H.rst new file mode 100644 index 00000000000000..472f61c5129e33 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2017-09-26-10-11-21.bpo-31583.TM90_H.rst @@ -0,0 +1,2 @@ +Fix 2to3 for using with --add-suffix option but without --output-dir +option for relative path to files in current directory. diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-03-02-16-23-31.bpo-25427.1mgMOG.rst b/Misc/NEWS.d/next/Tools-Demos/2018-03-02-16-23-31.bpo-25427.1mgMOG.rst new file mode 100644 index 00000000000000..fe4495e8b5740c --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2018-03-02-16-23-31.bpo-25427.1mgMOG.rst @@ -0,0 +1,3 @@ +Remove the pyvenv script in favor of ``python3 -m venv`` in order to lower +confusion as to what Python interpreter a virtual environment will be +created for. diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-04-03-18-10-00.bpo-33189.QrXR00.rst b/Misc/NEWS.d/next/Tools-Demos/2018-04-03-18-10-00.bpo-33189.QrXR00.rst new file mode 100644 index 00000000000000..4d4137240e61aa --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2018-04-03-18-10-00.bpo-33189.QrXR00.rst @@ -0,0 +1,2 @@ +:program:`pygettext.py` now recognizes only literal strings as docstrings +and translatable strings, and rejects bytes literals and f-string expressions. diff --git a/Modules/Setup.dist b/Modules/Setup.dist index a833774a153801..da2404a44a269f 100644 --- a/Modules/Setup.dist +++ b/Modules/Setup.dist @@ -104,33 +104,33 @@ PYTHONPATH=$(COREPYTHONPATH) # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. -posix posixmodule.c # posix (UNIX) system calls -errno errnomodule.c # posix (UNIX) errno values -pwd pwdmodule.c # this is needed to find out the user's home dir - # if $HOME is not set -_sre _sre.c # Fredrik Lundh's new regular expressions -_codecs _codecsmodule.c # access to the builtin codecs and codec registry -_weakref _weakref.c # weak references -_functools _functoolsmodule.c # Tools for working with functions and callable objects -_operator _operator.c # operator.add() and similar goodies -_collections _collectionsmodule.c # Container types -_abc _abc.c # Abstract base classes -itertools itertoolsmodule.c # Functions creating iterators for efficient looping -atexit atexitmodule.c # Register functions to be run at interpreter-shutdown -_signal signalmodule.c -_stat _stat.c # stat.h interface -time timemodule.c # -lm # time operations and variables -_thread _threadmodule.c # low-level threading interface +posix -DPy_BUILD_CORE posixmodule.c # posix (UNIX) system calls +errno errnomodule.c # posix (UNIX) errno values +pwd pwdmodule.c # this is needed to find out the user's home dir + # if $HOME is not set +_sre _sre.c # Fredrik Lundh's new regular expressions +_codecs _codecsmodule.c # access to the builtin codecs and codec registry +_weakref _weakref.c # weak references +_functools -DPy_BUILD_CORE _functoolsmodule.c # Tools for working with functions and callable objects +_operator _operator.c # operator.add() and similar goodies +_collections _collectionsmodule.c # Container types +_abc _abc.c # Abstract base classes +itertools itertoolsmodule.c # Functions creating iterators for efficient looping +atexit atexitmodule.c # Register functions to be run at interpreter-shutdown +_signal -DPy_BUILD_CORE signalmodule.c +_stat _stat.c # stat.h interface +time -DPy_BUILD_CORE timemodule.c # -lm # time operations and variables +_thread -DPy_BUILD_CORE _threadmodule.c # low-level threading interface # access to ISO C locale support _locale _localemodule.c # -lintl # Standard I/O baseline -_io -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c +_io -DPy_BUILD_CORE -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c # The zipimport module is always imported at startup. Having it as a # builtin module avoids some bootstrapping problems and reduces overhead. -zipimport zipimport.c +zipimport -DPy_BUILD_CORE zipimport.c # faulthandler module faulthandler faulthandler.c diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 5753dd946a5ad5..55132e786d5bf2 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -512,7 +512,7 @@ deque_inplace_concat(dequeobject *deque, PyObject *other) } static PyObject * -deque_copy(PyObject *deque) +deque_copy(PyObject *deque, PyObject *Py_UNUSED(ignored)) { dequeobject *old_deque = (dequeobject *)deque; if (Py_TYPE(deque) == &deque_type) { @@ -563,7 +563,7 @@ deque_concat(dequeobject *deque, PyObject *other) return NULL; } - new_deque = deque_copy((PyObject *)deque); + new_deque = deque_copy((PyObject *)deque, NULL); if (new_deque == NULL) return NULL; result = deque_extend((dequeobject *)new_deque, other); @@ -659,7 +659,7 @@ deque_clear(dequeobject *deque) } static PyObject * -deque_clearmethod(dequeobject *deque) +deque_clearmethod(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { deque_clear(deque); Py_RETURN_NONE; @@ -754,7 +754,7 @@ deque_repeat(dequeobject *deque, Py_ssize_t n) dequeobject *new_deque; PyObject *rv; - new_deque = (dequeobject *)deque_copy((PyObject *) deque); + new_deque = (dequeobject *)deque_copy((PyObject *) deque, NULL); if (new_deque == NULL) return NULL; rv = deque_inplace_repeat(new_deque, n); @@ -1576,7 +1576,7 @@ static PyNumberMethods deque_as_number = { }; static PyObject *deque_iter(dequeobject *deque); -static PyObject *deque_reviter(dequeobject *deque); +static PyObject *deque_reviter(dequeobject *deque, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(reversed_doc, "D.__reversed__() -- return a reverse iterator over the deque"); @@ -1587,9 +1587,9 @@ static PyMethodDef deque_methods[] = { METH_O, appendleft_doc}, {"clear", (PyCFunction)deque_clearmethod, METH_NOARGS, clear_doc}, - {"__copy__", (PyCFunction)deque_copy, + {"__copy__", deque_copy, METH_NOARGS, copy_doc}, - {"copy", (PyCFunction)deque_copy, + {"copy", deque_copy, METH_NOARGS, copy_doc}, {"count", (PyCFunction)deque_count, METH_O, count_doc}, @@ -1774,7 +1774,7 @@ dequeiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } static PyObject * -dequeiter_len(dequeiterobject *it) +dequeiter_len(dequeiterobject *it, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(it->counter); } @@ -1782,7 +1782,7 @@ dequeiter_len(dequeiterobject *it) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -dequeiter_reduce(dequeiterobject *it) +dequeiter_reduce(dequeiterobject *it, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(On)", Py_TYPE(it), it->deque, Py_SIZE(it->deque) - it->counter); } @@ -1841,7 +1841,7 @@ static PyTypeObject dequeiter_type = { static PyTypeObject dequereviter_type; static PyObject * -deque_reviter(dequeobject *deque) +deque_reviter(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { dequeiterobject *it; @@ -1896,7 +1896,7 @@ dequereviter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; assert(type == &dequereviter_type); - it = (dequeiterobject*)deque_reviter((dequeobject *)deque); + it = (dequeiterobject*)deque_reviter((dequeobject *)deque, NULL); if (!it) return NULL; /* consume items from the queue */ @@ -2001,7 +2001,7 @@ defdict_missing(defdictobject *dd, PyObject *key) PyDoc_STRVAR(defdict_copy_doc, "D.copy() -> a shallow copy of D."); static PyObject * -defdict_copy(defdictobject *dd) +defdict_copy(defdictobject *dd, PyObject *Py_UNUSED(ignored)) { /* This calls the object's class. That only works for subclasses whose class constructor has the same signature. Subclasses that @@ -2015,7 +2015,7 @@ defdict_copy(defdictobject *dd) } static PyObject * -defdict_reduce(defdictobject *dd) +defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) { /* __reduce__ must return a 5-tuple as follows: diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 6855903bdd5772..cc7eee6fd7f7d8 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2590,7 +2590,7 @@ delta_getstate(PyDateTime_Delta *self) } static PyObject * -delta_total_seconds(PyObject *self) +delta_total_seconds(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *total_seconds; PyObject *total_microseconds; @@ -2606,7 +2606,7 @@ delta_total_seconds(PyObject *self) } static PyObject * -delta_reduce(PyDateTime_Delta* self) +delta_reduce(PyDateTime_Delta* self, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("ON", Py_TYPE(self), delta_getstate(self)); } @@ -2627,7 +2627,7 @@ static PyMemberDef delta_members[] = { }; static PyMethodDef delta_methods[] = { - {"total_seconds", (PyCFunction)delta_total_seconds, METH_NOARGS, + {"total_seconds", delta_total_seconds, METH_NOARGS, PyDoc_STR("Total seconds in the duration.")}, {"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS, @@ -2991,7 +2991,7 @@ date_repr(PyDateTime_Date *self) } static PyObject * -date_isoformat(PyDateTime_Date *self) +date_isoformat(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { return PyUnicode_FromFormat("%04d-%02d-%02d", GET_YEAR(self), GET_MONTH(self), GET_DAY(self)); @@ -3006,7 +3006,7 @@ date_str(PyDateTime_Date *self) static PyObject * -date_ctime(PyDateTime_Date *self) +date_ctime(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { return format_ctime(self, 0, 0, 0); } @@ -3055,7 +3055,7 @@ date_format(PyDateTime_Date *self, PyObject *args) /* ISO methods. */ static PyObject * -date_isoweekday(PyDateTime_Date *self) +date_isoweekday(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self)); @@ -3063,7 +3063,7 @@ date_isoweekday(PyDateTime_Date *self) } static PyObject * -date_isocalendar(PyDateTime_Date *self) +date_isocalendar(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { int year = GET_YEAR(self); int week1_monday = iso_week1_monday(year); @@ -3100,7 +3100,7 @@ date_richcompare(PyObject *self, PyObject *other, int op) } static PyObject * -date_timetuple(PyDateTime_Date *self) +date_timetuple(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { return build_struct_time(GET_YEAR(self), GET_MONTH(self), @@ -3149,14 +3149,14 @@ date_hash(PyDateTime_Date *self) } static PyObject * -date_toordinal(PyDateTime_Date *self) +date_toordinal(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self), GET_DAY(self))); } static PyObject * -date_weekday(PyDateTime_Date *self) +date_weekday(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored)) { int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self)); @@ -3435,7 +3435,7 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt) */ static PyObject * -tzinfo_reduce(PyObject *self) +tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *args, *state; PyObject *getinitargs, *getstate; @@ -3502,7 +3502,7 @@ static PyMethodDef tzinfo_methods[] = { {"fromutc", (PyCFunction)tzinfo_fromutc, METH_O, PyDoc_STR("datetime in UTC -> datetime in local time.")}, - {"__reduce__", (PyCFunction)tzinfo_reduce, METH_NOARGS, + {"__reduce__", tzinfo_reduce, METH_NOARGS, PyDoc_STR("-> (cls, state)")}, {NULL, NULL} @@ -3720,7 +3720,7 @@ timezone_fromutc(PyDateTime_TimeZone *self, PyDateTime_DateTime *dt) } static PyObject * -timezone_getinitargs(PyDateTime_TimeZone *self) +timezone_getinitargs(PyDateTime_TimeZone *self, PyObject *Py_UNUSED(ignored)) { if (self->name == NULL) return Py_BuildValue("(O)", self->offset); @@ -5173,7 +5173,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw) } static PyObject * -datetime_ctime(PyDateTime_DateTime *self) +datetime_ctime(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { return format_ctime((PyDateTime_Date *)self, DATE_GET_HOUR(self), @@ -5652,7 +5652,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw) } static PyObject * -datetime_timetuple(PyDateTime_DateTime *self) +datetime_timetuple(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { int dstflag = -1; @@ -5727,7 +5727,7 @@ local_to_seconds(int year, int month, int day, #define EPOCH_SECONDS (719163LL * 24 * 60 * 60) static PyObject * -datetime_timestamp(PyDateTime_DateTime *self) +datetime_timestamp(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { PyObject *result; @@ -5736,7 +5736,7 @@ datetime_timestamp(PyDateTime_DateTime *self) delta = datetime_subtract((PyObject *)self, PyDateTime_Epoch); if (delta == NULL) return NULL; - result = delta_total_seconds(delta); + result = delta_total_seconds(delta, NULL); Py_DECREF(delta); } else { @@ -5757,7 +5757,7 @@ datetime_timestamp(PyDateTime_DateTime *self) } static PyObject * -datetime_getdate(PyDateTime_DateTime *self) +datetime_getdate(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { return new_date(GET_YEAR(self), GET_MONTH(self), @@ -5765,7 +5765,7 @@ datetime_getdate(PyDateTime_DateTime *self) } static PyObject * -datetime_gettime(PyDateTime_DateTime *self) +datetime_gettime(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { return new_time(DATE_GET_HOUR(self), DATE_GET_MINUTE(self), @@ -5776,7 +5776,7 @@ datetime_gettime(PyDateTime_DateTime *self) } static PyObject * -datetime_gettimetz(PyDateTime_DateTime *self) +datetime_gettimetz(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { return new_time(DATE_GET_HOUR(self), DATE_GET_MINUTE(self), @@ -5787,7 +5787,7 @@ datetime_gettimetz(PyDateTime_DateTime *self) } static PyObject * -datetime_utctimetuple(PyDateTime_DateTime *self) +datetime_utctimetuple(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored)) { int y, m, d, hh, mm, ss; PyObject *tzinfo; diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index 8afd92cf3ca868..65761d83d380f7 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -274,7 +274,7 @@ static PySequenceMethods dbm_as_sequence = { _dbm.dbm.get key: str(accept={str, robuffer}, zeroes=True) - default: object(c_default="NULL") = b'' + default: object = None / Return the value for key if present, otherwise default. @@ -283,7 +283,7 @@ Return the value for key if present, otherwise default. static PyObject * _dbm_dbm_get_impl(dbmobject *self, const char *key, Py_ssize_clean_t key_length, PyObject *default_value) -/*[clinic end generated code: output=b44f95eba8203d93 input=a3a279957f85eb6d]*/ +/*[clinic end generated code: output=b44f95eba8203d93 input=b788eba0ffad2e91]*/ /*[clinic end generated code: output=4f5c0e523eaf1251 input=9402c0af8582dc69]*/ { datum dbm_key, val; diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index ba33f8c50d6aad..a50add2389e561 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -758,7 +758,7 @@ _io_BytesIO_close_impl(bytesio *self) */ static PyObject * -bytesio_getstate(bytesio *self) +bytesio_getstate(bytesio *self, PyObject *Py_UNUSED(ignored)) { PyObject *initvalue = _io_BytesIO_getvalue_impl(self); PyObject *dict; diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 0d5bf3b22114e5..c0e43e0ae41a8f 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -1123,7 +1123,7 @@ _io_FileIO_isatty_impl(fileio *self) } static PyObject * -fileio_getstate(fileio *self) +fileio_getstate(fileio *self, PyObject *Py_UNUSED(ignored)) { PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", Py_TYPE(self)->tp_name); diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index 718b1ac1d82db2..f280b30c812aea 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -812,7 +812,7 @@ _io_StringIO_seekable_impl(stringio *self) */ static PyObject * -stringio_getstate(stringio *self) +stringio_getstate(stringio *self, PyObject *Py_UNUSED(ignored)) { PyObject *initvalue = _io_StringIO_getvalue_impl(self); PyObject *dict; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 717b56ab319b61..209aa13cbd17d3 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -66,7 +66,7 @@ PyDoc_STRVAR(textiobase_detach_doc, ); static PyObject * -textiobase_detach(PyObject *self) +textiobase_detach(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _unsupported("detach"); } @@ -148,7 +148,7 @@ textiobase_errors_get(PyObject *self, void *context) static PyMethodDef textiobase_methods[] = { - {"detach", (PyCFunction)textiobase_detach, METH_NOARGS, textiobase_detach_doc}, + {"detach", textiobase_detach, METH_NOARGS, textiobase_detach_doc}, {"read", textiobase_read, METH_VARARGS, textiobase_read_doc}, {"readline", textiobase_readline, METH_VARARGS, textiobase_readline_doc}, {"write", textiobase_write, METH_VARARGS, textiobase_write_doc}, diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index b85c11b3405a73..2bf48eb55532d8 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -1057,7 +1057,7 @@ _io__WindowsConsoleIO_isatty_impl(winconsoleio *self) } static PyObject * -winconsoleio_getstate(winconsoleio *self) +winconsoleio_getstate(winconsoleio *self, PyObject *Py_UNUSED(ignored)) { PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object", Py_TYPE(self)->tp_name); diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index f9eeeb72dd9e1e..524886d466009b 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -132,7 +132,7 @@ PyDoc_STRVAR(localeconv__doc__, "() -> dict. Returns numeric and monetary locale-specific parameters."); static PyObject* -PyLocale_localeconv(PyObject* self) +PyLocale_localeconv(PyObject* self, PyObject *Py_UNUSED(ignored)) { PyObject* result; struct lconv *l; @@ -317,7 +317,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args) #if defined(MS_WINDOWS) static PyObject* -PyLocale_getdefaultlocale(PyObject* self) +PyLocale_getdefaultlocale(PyObject* self, PyObject *Py_UNUSED(ignored)) { char encoding[100]; char locale[100]; @@ -605,8 +605,7 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args) static struct PyMethodDef PyLocale_Methods[] = { {"setlocale", (PyCFunction) PyLocale_setlocale, METH_VARARGS, setlocale__doc__}, - {"localeconv", (PyCFunction) PyLocale_localeconv, - METH_NOARGS, localeconv__doc__}, + {"localeconv", PyLocale_localeconv, METH_NOARGS, localeconv__doc__}, #ifdef HAVE_WCSCOLL {"strcoll", (PyCFunction) PyLocale_strcoll, METH_VARARGS, strcoll__doc__}, @@ -616,7 +615,7 @@ static struct PyMethodDef PyLocale_Methods[] = { METH_VARARGS, strxfrm__doc__}, #endif #if defined(MS_WINDOWS) - {"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, METH_NOARGS}, + {"_getdefaultlocale", PyLocale_getdefaultlocale, METH_NOARGS}, #endif #ifdef HAVE_LANGINFO_H {"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo, diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 0092b139346416..b1d3a216cbe83a 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -518,20 +518,20 @@ semlock_dealloc(SemLockObject* self) } static PyObject * -semlock_count(SemLockObject *self) +semlock_count(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong((long)self->count); } static PyObject * -semlock_ismine(SemLockObject *self) +semlock_ismine(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { /* only makes sense for a lock */ return PyBool_FromLong(ISMINE(self)); } static PyObject * -semlock_getvalue(SemLockObject *self) +semlock_getvalue(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { #ifdef HAVE_BROKEN_SEM_GETVALUE PyErr_SetNone(PyExc_NotImplementedError); @@ -549,7 +549,7 @@ semlock_getvalue(SemLockObject *self) } static PyObject * -semlock_iszero(SemLockObject *self) +semlock_iszero(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { #ifdef HAVE_BROKEN_SEM_GETVALUE if (sem_trywait(self->handle) < 0) { @@ -570,7 +570,7 @@ semlock_iszero(SemLockObject *self) } static PyObject * -semlock_afterfork(SemLockObject *self) +semlock_afterfork(SemLockObject *self, PyObject *Py_UNUSED(ignored)) { self->count = 0; Py_RETURN_NONE; diff --git a/Modules/_operator.c b/Modules/_operator.c index f2fd65695f2e0e..dc678209ad3db3 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1040,7 +1040,7 @@ itemgetter_repr(itemgetterobject *ig) } static PyObject * -itemgetter_reduce(itemgetterobject *ig) +itemgetter_reduce(itemgetterobject *ig, PyObject *Py_UNUSED(ignored)) { if (ig->nitems == 1) return Py_BuildValue("O(O)", Py_TYPE(ig), ig->item); @@ -1382,7 +1382,7 @@ attrgetter_repr(attrgetterobject *ag) } static PyObject * -attrgetter_reduce(attrgetterobject *ag) +attrgetter_reduce(attrgetterobject *ag, PyObject *Py_UNUSED(ignored)) { PyObject *attrstrings = attrgetter_args(ag); if (attrstrings == NULL) @@ -1615,7 +1615,7 @@ methodcaller_repr(methodcallerobject *mc) } static PyObject * -methodcaller_reduce(methodcallerobject *mc) +methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored)) { PyObject *newargs; if (!mc->kwds || PyDict_GET_SIZE(mc->kwds) == 0) { diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 51677f8b00a492..dae9d42fcb225c 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -138,7 +138,7 @@ genrand_int32(RandomObject *self) * The original code credited Isaku Wada for this algorithm, 2002/01/09. */ static PyObject * -random_random(RandomObject *self) +random_random(RandomObject *self, PyObject *Py_UNUSED(ignored)) { uint32_t a=genrand_int32(self)>>5, b=genrand_int32(self)>>6; return PyFloat_FromDouble((a*67108864.0+b)*(1.0/9007199254740992.0)); @@ -319,7 +319,7 @@ random_seed(RandomObject *self, PyObject *args) } static PyObject * -random_getstate(RandomObject *self) +random_getstate(RandomObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *state; PyObject *element; diff --git a/Modules/_scproxy.c b/Modules/_scproxy.c index 0e3b02879b833d..8861dc456d759a 100644 --- a/Modules/_scproxy.c +++ b/Modules/_scproxy.c @@ -53,7 +53,7 @@ cfstring_to_pystring(CFStringRef ref) static PyObject* -get_proxy_settings(PyObject* mod __attribute__((__unused__))) +get_proxy_settings(PyObject* Py_UNUSED(mod), PyObject *Py_UNUSED(ignored)) { CFDictionaryRef proxyDict = NULL; CFNumberRef aNum = NULL; @@ -166,7 +166,7 @@ set_proxy(PyObject* proxies, const char* proto, CFDictionaryRef proxyDict, static PyObject* -get_proxies(PyObject* mod __attribute__((__unused__))) +get_proxies(PyObject* Py_UNUSED(mod), PyObject *Py_UNUSED(ignored)) { PyObject* result = NULL; int r; @@ -212,13 +212,13 @@ get_proxies(PyObject* mod __attribute__((__unused__))) static PyMethodDef mod_methods[] = { { "_get_proxy_settings", - (PyCFunction)get_proxy_settings, + get_proxy_settings, METH_NOARGS, NULL, }, { "_get_proxies", - (PyCFunction)get_proxies, + get_proxies, METH_NOARGS, NULL, }, diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index ec2c788ae7c046..64872e8ddfc157 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -155,7 +155,7 @@ Py_ssize_t pysqlite_row_length(pysqlite_Row* self, PyObject* args, PyObject* kwa return PyTuple_GET_SIZE(self->data); } -PyObject* pysqlite_row_keys(pysqlite_Row* self, PyObject* args, PyObject* kwargs) +PyObject* pysqlite_row_keys(pysqlite_Row* self, PyObject *Py_UNUSED(ignored)) { PyObject* list; Py_ssize_t nitems, i; diff --git a/Modules/_struct.c b/Modules/_struct.c index 053970671f17c4..0be52d9ab94b01 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1629,7 +1629,7 @@ unpackiter_traverse(unpackiterobject *self, visitproc visit, void *arg) } static PyObject * -unpackiter_len(unpackiterobject *self) +unpackiter_len(unpackiterobject *self, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len; if (self->so == NULL) diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index 6b8ab34d931cd3..221543dcdd7cfd 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -2354,7 +2354,7 @@ get_pointer(PyObject *self, PyObject *args) } static PyObject * -get_sizeof_void_p(PyObject *self) +get_sizeof_void_p(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSize_t(sizeof(void *)); } @@ -2807,7 +2807,7 @@ static PyTypeObject StaticArray_Type = { static struct PyMethodDef _testbuffer_functions[] = { {"slice_indices", slice_indices, METH_VARARGS, NULL}, {"get_pointer", get_pointer, METH_VARARGS, NULL}, - {"get_sizeof_void_p", (PyCFunction)get_sizeof_void_p, METH_NOARGS, NULL}, + {"get_sizeof_void_p", get_sizeof_void_p, METH_NOARGS, NULL}, {"get_contiguous", get_contiguous, METH_VARARGS, NULL}, {"py_buffer_to_contiguous", py_buffer_to_contiguous, METH_VARARGS, NULL}, {"is_contiguous", is_contiguous, METH_VARARGS, NULL}, diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index afce6c9448952b..0e48463976e4d2 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -51,7 +51,7 @@ sizeof_error(const char* fatname, const char* typname, } static PyObject* -test_config(PyObject *self) +test_config(PyObject *self, PyObject *Py_UNUSED(ignored)) { #define CHECK_SIZEOF(FATNAME, TYPE) \ if (FATNAME != sizeof(TYPE)) \ @@ -70,7 +70,7 @@ test_config(PyObject *self) } static PyObject* -test_sizeof_c_types(PyObject *self) +test_sizeof_c_types(PyObject *self, PyObject *Py_UNUSED(ignored)) { #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))) #pragma GCC diagnostic push @@ -131,7 +131,7 @@ test_sizeof_c_types(PyObject *self) static PyObject* -test_list_api(PyObject *self) +test_list_api(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* list; int i; @@ -223,7 +223,7 @@ test_dict_inner(int count) } static PyObject* -test_dict_iteration(PyObject* self) +test_dict_iteration(PyObject* self, PyObject *Py_UNUSED(ignored)) { int i; @@ -315,7 +315,7 @@ static PyTypeObject _HashInheritanceTester_Type = { }; static PyObject* -test_lazy_hash_inheritance(PyObject* self) +test_lazy_hash_inheritance(PyObject* self, PyObject *Py_UNUSED(ignored)) { PyTypeObject *type; PyObject *obj; @@ -411,7 +411,7 @@ raise_test_long_error(const char* msg) #include "testcapi_long.h" static PyObject * -test_long_api(PyObject* self) +test_long_api(PyObject* self, PyObject *Py_UNUSED(ignored)) { return TESTNAME(raise_test_long_error); } @@ -457,7 +457,7 @@ test_longlong_api(PyObject* self, PyObject *args) */ static PyObject * -test_long_and_overflow(PyObject *self) +test_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *num, *one, *temp; long value; @@ -621,7 +621,7 @@ test_long_and_overflow(PyObject *self) */ static PyObject * -test_long_long_and_overflow(PyObject *self) +test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *num, *one, *temp; long long value; @@ -785,7 +785,7 @@ test_long_long_and_overflow(PyObject *self) */ static PyObject * -test_long_as_size_t(PyObject *self) +test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored)) { size_t out_u; Py_ssize_t out_s; @@ -821,7 +821,7 @@ test_long_as_size_t(PyObject *self) */ static PyObject * -test_long_as_double(PyObject *self) +test_long_as_double(PyObject *self, PyObject *Py_UNUSED(ignored)) { double out; @@ -846,7 +846,7 @@ test_long_as_double(PyObject *self) it fails. */ static PyObject * -test_L_code(PyObject *self) +test_L_code(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *tuple, *num; long long value; @@ -1173,7 +1173,7 @@ getargs_K(PyObject *self, PyObject *args) /* This function not only tests the 'k' getargs code, but also the PyLong_AsUnsignedLongMask() function. */ static PyObject * -test_k_code(PyObject *self) +test_k_code(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *tuple, *num; unsigned long value; @@ -1531,7 +1531,7 @@ getargs_et_hash(PyObject *self, PyObject *args) /* Test the s and z codes for PyArg_ParseTuple. */ static PyObject * -test_s_code(PyObject *self) +test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored)) { /* Unicode strings should be accepted */ PyObject *tuple, *obj; @@ -1637,7 +1637,7 @@ static volatile int x; of an error. */ static PyObject * -test_u_code(PyObject *self) +test_u_code(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *tuple, *obj; Py_UNICODE *value; @@ -1680,7 +1680,7 @@ test_u_code(PyObject *self) /* Test Z and Z# codes for PyArg_ParseTuple */ static PyObject * -test_Z_code(PyObject *self) +test_Z_code(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *tuple, *obj; const Py_UNICODE *value1, *value2; @@ -1735,7 +1735,7 @@ test_Z_code(PyObject *self) } static PyObject * -test_widechar(PyObject *self) +test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored)) { #if defined(SIZEOF_WCHAR_T) && (SIZEOF_WCHAR_T == 4) const wchar_t wtext[2] = {(wchar_t)0x10ABCDu}; @@ -2033,7 +2033,7 @@ getargs_w_star(PyObject *self, PyObject *args) static PyObject * -test_empty_argparse(PyObject *self) +test_empty_argparse(PyObject *self, PyObject *Py_UNUSED(ignored)) { /* Test that formats can begin with '|'. See issue #4720. */ PyObject *tuple, *dict = NULL; @@ -2083,7 +2083,7 @@ codec_incrementaldecoder(PyObject *self, PyObject *args) /* Simple test of _PyLong_NumBits and _PyLong_Sign. */ static PyObject * -test_long_numbits(PyObject *self) +test_long_numbits(PyObject *self, PyObject *Py_UNUSED(ignored)) { struct triple { long input; @@ -2131,7 +2131,7 @@ test_long_numbits(PyObject *self) /* Example passing NULLs to PyObject_Str(NULL). */ static PyObject * -test_null_strings(PyObject *self) +test_null_strings(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Str(NULL); PyObject *tuple = PyTuple_Pack(2, o1, o2); @@ -2492,7 +2492,7 @@ test_string_from_format(PyObject *self, PyObject *args) static PyObject * -test_unicode_compare_with_ascii(PyObject *self) { +test_unicode_compare_with_ascii(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *py_s = PyUnicode_FromStringAndSize("str\0", 4); int result; if (py_s == NULL) @@ -2509,14 +2509,14 @@ test_unicode_compare_with_ascii(PyObject *self) { /* This is here to provide a docstring for test_descr. */ static PyObject * -test_with_docstring(PyObject *self) +test_with_docstring(PyObject *self, PyObject *Py_UNUSED(ignored)) { Py_RETURN_NONE; } /* Test PyOS_string_to_double. */ static PyObject * -test_string_to_double(PyObject *self) { +test_string_to_double(PyObject *self, PyObject *Py_UNUSED(ignored)) { double result; const char *msg; @@ -2881,7 +2881,7 @@ exception_print(PyObject *self, PyObject *args) /* reliably raise a MemoryError */ static PyObject * -raise_memoryerror(PyObject *self) +raise_memoryerror(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyErr_NoMemory(); return NULL; @@ -2954,7 +2954,7 @@ make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs) } static PyObject * -make_memoryview_from_NULL_pointer(PyObject *self) +make_memoryview_from_NULL_pointer(PyObject *self, PyObject *Py_UNUSED(ignored)) { Py_buffer info; if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0) @@ -3067,7 +3067,7 @@ getbuffer_with_null_view(PyObject* self, PyObject *obj) /* Test that the fatal error from not having a current thread doesn't cause an infinite loop. Run via Lib/test/test_capi.py */ static PyObject * -crash_no_current_thread(PyObject *self) +crash_no_current_thread(PyObject *self, PyObject *Py_UNUSED(ignored)) { Py_BEGIN_ALLOW_THREADS /* Using PyThreadState_Get() directly allows the test to pass in @@ -3274,7 +3274,7 @@ _test_incref(PyObject *ob) } static PyObject * -test_xincref_doesnt_leak(PyObject *ob) +test_xincref_doesnt_leak(PyObject *ob, PyObject *Py_UNUSED(ignored)) { PyObject *obj = PyLong_FromLong(0); Py_XINCREF(_test_incref(obj)); @@ -3285,7 +3285,7 @@ test_xincref_doesnt_leak(PyObject *ob) } static PyObject * -test_incref_doesnt_leak(PyObject *ob) +test_incref_doesnt_leak(PyObject *ob, PyObject *Py_UNUSED(ignored)) { PyObject *obj = PyLong_FromLong(0); Py_INCREF(_test_incref(obj)); @@ -3296,21 +3296,21 @@ test_incref_doesnt_leak(PyObject *ob) } static PyObject * -test_xdecref_doesnt_leak(PyObject *ob) +test_xdecref_doesnt_leak(PyObject *ob, PyObject *Py_UNUSED(ignored)) { Py_XDECREF(PyLong_FromLong(0)); Py_RETURN_NONE; } static PyObject * -test_decref_doesnt_leak(PyObject *ob) +test_decref_doesnt_leak(PyObject *ob, PyObject *Py_UNUSED(ignored)) { Py_DECREF(PyLong_FromLong(0)); Py_RETURN_NONE; } static PyObject * -test_incref_decref_API(PyObject *ob) +test_incref_decref_API(PyObject *ob, PyObject *Py_UNUSED(ignored)) { PyObject *obj = PyLong_FromLong(0); Py_IncRef(obj); @@ -3320,7 +3320,7 @@ test_incref_decref_API(PyObject *ob) } static PyObject * -test_pymem_alloc0(PyObject *self) +test_pymem_alloc0(PyObject *self, PyObject *Py_UNUSED(ignored)) { void *ptr; @@ -3546,19 +3546,19 @@ test_setallocators(PyMemAllocatorDomain domain) } static PyObject * -test_pymem_setrawallocators(PyObject *self) +test_pymem_setrawallocators(PyObject *self, PyObject *Py_UNUSED(ignored)) { return test_setallocators(PYMEM_DOMAIN_RAW); } static PyObject * -test_pymem_setallocators(PyObject *self) +test_pymem_setallocators(PyObject *self, PyObject *Py_UNUSED(ignored)) { return test_setallocators(PYMEM_DOMAIN_MEM); } static PyObject * -test_pyobject_setallocators(PyObject *self) +test_pyobject_setallocators(PyObject *self, PyObject *Py_UNUSED(ignored)) { return test_setallocators(PYMEM_DOMAIN_OBJ); } @@ -3681,7 +3681,7 @@ set_nomemory(PyObject *self, PyObject *args) } static PyObject* -remove_mem_hooks(PyObject *self) +remove_mem_hooks(PyObject *self, PyObject *Py_UNUSED(ignored)) { fm_remove_hooks(); Py_RETURN_NONE; @@ -4552,10 +4552,10 @@ new_hamt(PyObject *self, PyObject *args) static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, - {"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS}, + {"raise_memoryerror", raise_memoryerror, METH_NOARGS}, {"set_errno", set_errno, METH_VARARGS}, - {"test_config", (PyCFunction)test_config, METH_NOARGS}, - {"test_sizeof_c_types", (PyCFunction)test_sizeof_c_types, METH_NOARGS}, + {"test_config", test_config, METH_NOARGS}, + {"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS}, {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, {"datetime_check_date", datetime_check_date, METH_VARARGS}, {"datetime_check_time", datetime_check_time, METH_VARARGS}, @@ -4565,31 +4565,31 @@ static PyMethodDef TestMethods[] = { {"make_timezones_capi", make_timezones_capi, METH_NOARGS}, {"get_timezones_offset_zero", get_timezones_offset_zero, METH_NOARGS}, {"get_timezone_utc_capi", get_timezone_utc_capi, METH_VARARGS}, - {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, - {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, + {"test_list_api", test_list_api, METH_NOARGS}, + {"test_dict_iteration", test_dict_iteration, METH_NOARGS}, {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS}, {"dict_hassplittable", dict_hassplittable, METH_O}, - {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, - {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, - {"test_xincref_doesnt_leak",(PyCFunction)test_xincref_doesnt_leak, METH_NOARGS}, - {"test_incref_doesnt_leak", (PyCFunction)test_incref_doesnt_leak, METH_NOARGS}, - {"test_xdecref_doesnt_leak",(PyCFunction)test_xdecref_doesnt_leak, METH_NOARGS}, - {"test_decref_doesnt_leak", (PyCFunction)test_decref_doesnt_leak, METH_NOARGS}, - {"test_incref_decref_API", (PyCFunction)test_incref_decref_API, METH_NOARGS}, - {"test_long_and_overflow", (PyCFunction)test_long_and_overflow, - METH_NOARGS}, - {"test_long_as_double", (PyCFunction)test_long_as_double,METH_NOARGS}, - {"test_long_as_size_t", (PyCFunction)test_long_as_size_t,METH_NOARGS}, - {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, - {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, - {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, + {"test_lazy_hash_inheritance", test_lazy_hash_inheritance,METH_NOARGS}, + {"test_long_api", test_long_api, METH_NOARGS}, + {"test_xincref_doesnt_leak",test_xincref_doesnt_leak, METH_NOARGS}, + {"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS}, + {"test_xdecref_doesnt_leak",test_xdecref_doesnt_leak, METH_NOARGS}, + {"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS}, + {"test_incref_decref_API", test_incref_decref_API, METH_NOARGS}, + {"test_long_and_overflow", test_long_and_overflow, METH_NOARGS}, + {"test_long_as_double", test_long_as_double, METH_NOARGS}, + {"test_long_as_size_t", test_long_as_size_t, METH_NOARGS}, + {"test_long_numbits", test_long_numbits, METH_NOARGS}, + {"test_k_code", test_k_code, METH_NOARGS}, + {"test_empty_argparse", test_empty_argparse, METH_NOARGS}, {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, - {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, + {"test_null_strings", test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, - {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, + {"test_with_docstring", test_with_docstring, METH_NOARGS, PyDoc_STR("This is a pretty normal docstring.")}, - {"test_string_to_double", (PyCFunction)test_string_to_double, METH_NOARGS}, - {"test_unicode_compare_with_ascii", (PyCFunction)test_unicode_compare_with_ascii, METH_NOARGS}, + {"test_string_to_double", test_string_to_double, METH_NOARGS}, + {"test_unicode_compare_with_ascii", test_unicode_compare_with_ascii, + METH_NOARGS}, {"test_capsule", (PyCFunction)test_capsule, METH_NOARGS}, {"test_from_contiguous", (PyCFunction)test_from_contiguous, METH_NOARGS}, #if (defined(__linux__) || defined(__FreeBSD__)) && defined(__GNUC__) @@ -4620,9 +4620,8 @@ static PyMethodDef TestMethods[] = { {"getargs_L", getargs_L, METH_VARARGS}, {"getargs_K", getargs_K, METH_VARARGS}, {"test_longlong_api", test_longlong_api, METH_NOARGS}, - {"test_long_long_and_overflow", - (PyCFunction)test_long_long_and_overflow, METH_NOARGS}, - {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, + {"test_long_long_and_overflow",test_long_long_and_overflow, METH_NOARGS}, + {"test_L_code", test_L_code, METH_NOARGS}, {"getargs_f", getargs_f, METH_VARARGS}, {"getargs_d", getargs_d, METH_VARARGS}, {"getargs_D", getargs_D, METH_VARARGS}, @@ -4653,10 +4652,10 @@ static PyMethodDef TestMethods[] = { (PyCFunction)codec_incrementalencoder, METH_VARARGS}, {"codec_incrementaldecoder", (PyCFunction)codec_incrementaldecoder, METH_VARARGS}, - {"test_s_code", (PyCFunction)test_s_code, METH_NOARGS}, - {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS}, - {"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS}, - {"test_widechar", (PyCFunction)test_widechar, METH_NOARGS}, + {"test_s_code", test_s_code, METH_NOARGS}, + {"test_u_code", test_u_code, METH_NOARGS}, + {"test_Z_code", test_Z_code, METH_NOARGS}, + {"test_widechar", test_widechar, METH_NOARGS}, {"unicode_aswidechar", unicode_aswidechar, METH_VARARGS}, {"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS}, {"unicode_asucs4", unicode_asucs4, METH_VARARGS}, @@ -4677,26 +4676,22 @@ static PyMethodDef TestMethods[] = { {"code_newempty", code_newempty, METH_VARARGS}, {"make_exception_with_doc", (PyCFunction)make_exception_with_doc, METH_VARARGS | METH_KEYWORDS}, - {"make_memoryview_from_NULL_pointer", (PyCFunction)make_memoryview_from_NULL_pointer, + {"make_memoryview_from_NULL_pointer", make_memoryview_from_NULL_pointer, METH_NOARGS}, - {"crash_no_current_thread", (PyCFunction)crash_no_current_thread, METH_NOARGS}, + {"crash_no_current_thread", crash_no_current_thread, METH_NOARGS}, {"run_in_subinterp", run_in_subinterp, METH_VARARGS}, {"pytime_object_to_time_t", test_pytime_object_to_time_t, METH_VARARGS}, {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, {"with_tp_del", with_tp_del, METH_VARARGS}, {"create_cfunction", create_cfunction, METH_NOARGS}, - {"test_pymem_alloc0", - (PyCFunction)test_pymem_alloc0, METH_NOARGS}, - {"test_pymem_setrawallocators", - (PyCFunction)test_pymem_setrawallocators, METH_NOARGS}, - {"test_pymem_setallocators", - (PyCFunction)test_pymem_setallocators, METH_NOARGS}, - {"test_pyobject_setallocators", - (PyCFunction)test_pyobject_setallocators, METH_NOARGS}, + {"test_pymem_alloc0", test_pymem_alloc0, METH_NOARGS}, + {"test_pymem_setrawallocators",test_pymem_setrawallocators, METH_NOARGS}, + {"test_pymem_setallocators",test_pymem_setallocators, METH_NOARGS}, + {"test_pyobject_setallocators",test_pyobject_setallocators, METH_NOARGS}, {"set_nomemory", (PyCFunction)set_nomemory, METH_VARARGS, PyDoc_STR("set_nomemory(start:int, stop:int = 0)")}, - {"remove_mem_hooks", (PyCFunction)remove_mem_hooks, METH_NOARGS, + {"remove_mem_hooks", remove_mem_hooks, METH_NOARGS, PyDoc_STR("Remove memory hooks.")}, {"no_docstring", (PyCFunction)test_with_docstring, METH_NOARGS}, diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 43898d838bea09..69e27be9cc81a4 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -163,7 +163,7 @@ and the return value reflects whether the lock is acquired.\n\ The blocking operation is interruptible."); static PyObject * -lock_PyThread_release_lock(lockobject *self) +lock_PyThread_release_lock(lockobject *self, PyObject *Py_UNUSED(ignored)) { /* Sanity check: the lock must be locked */ if (!self->locked) { @@ -185,7 +185,7 @@ the lock to acquire the lock. The lock must be in the locked state,\n\ but it needn't be locked by the same thread that unlocks it."); static PyObject * -lock_locked_lock(lockobject *self) +lock_locked_lock(lockobject *self, PyObject *Py_UNUSED(ignored)) { return PyBool_FromLong((long)self->locked); } @@ -333,7 +333,7 @@ internal counter is simply incremented. If nobody holds the lock,\n\ the lock is taken and its internal counter initialized to 1."); static PyObject * -rlock_release(rlockobject *self) +rlock_release(rlockobject *self, PyObject *Py_UNUSED(ignored)) { unsigned long tid = PyThread_get_thread_ident(); @@ -392,7 +392,7 @@ PyDoc_STRVAR(rlock_acquire_restore_doc, For internal use by `threading.Condition`."); static PyObject * -rlock_release_save(rlockobject *self) +rlock_release_save(rlockobject *self, PyObject *Py_UNUSED(ignored)) { unsigned long owner; unsigned long count; @@ -418,7 +418,7 @@ For internal use by `threading.Condition`."); static PyObject * -rlock_is_owned(rlockobject *self) +rlock_is_owned(rlockobject *self, PyObject *Py_UNUSED(ignored)) { unsigned long tid = PyThread_get_thread_ident(); @@ -1087,7 +1087,7 @@ when the function raises an unhandled exception; a stack trace will be\n\ printed unless the exception is SystemExit.\n"); static PyObject * -thread_PyThread_exit_thread(PyObject *self) +thread_PyThread_exit_thread(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyErr_SetNone(PyExc_SystemExit); return NULL; @@ -1101,7 +1101,7 @@ This is synonymous to ``raise SystemExit''. It will cause the current\n\ thread to exit silently unless the exception is caught."); static PyObject * -thread_PyThread_interrupt_main(PyObject * self) +thread_PyThread_interrupt_main(PyObject * self, PyObject *Py_UNUSED(ignored)) { PyErr_SetInterrupt(); Py_RETURN_NONE; @@ -1117,7 +1117,7 @@ A subthread can use this function to interrupt the main thread." static lockobject *newlockobject(void); static PyObject * -thread_PyThread_allocate_lock(PyObject *self) +thread_PyThread_allocate_lock(PyObject *self, PyObject *Py_UNUSED(ignored)) { return (PyObject *) newlockobject(); } @@ -1130,7 +1130,7 @@ Create a new lock object. See help(type(threading.Lock())) for\n\ information about locks."); static PyObject * -thread_get_ident(PyObject *self) +thread_get_ident(PyObject *self, PyObject *Py_UNUSED(ignored)) { unsigned long ident = PyThread_get_thread_ident(); if (ident == PYTHREAD_INVALID_THREAD_ID) { @@ -1152,7 +1152,7 @@ be relied upon, and the number should be seen purely as a magic cookie.\n\ A thread's identity may be reused for another thread after it exits."); static PyObject * -thread__count(PyObject *self) +thread__count(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyThreadState *tstate = PyThreadState_Get(); return PyLong_FromLong(tstate->interp->num_threads); @@ -1192,7 +1192,7 @@ release_sentinel(void *wr) } static PyObject * -thread__set_sentinel(PyObject *self) +thread__set_sentinel(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *wr; PyThreadState *tstate = PyThreadState_Get(); @@ -1289,23 +1289,23 @@ static PyMethodDef thread_methods[] = { METH_VARARGS, start_new_doc}, {"start_new", (PyCFunction)thread_PyThread_start_new_thread, METH_VARARGS, start_new_doc}, - {"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock, + {"allocate_lock", thread_PyThread_allocate_lock, METH_NOARGS, allocate_doc}, - {"allocate", (PyCFunction)thread_PyThread_allocate_lock, + {"allocate", thread_PyThread_allocate_lock, METH_NOARGS, allocate_doc}, - {"exit_thread", (PyCFunction)thread_PyThread_exit_thread, + {"exit_thread", thread_PyThread_exit_thread, METH_NOARGS, exit_doc}, - {"exit", (PyCFunction)thread_PyThread_exit_thread, + {"exit", thread_PyThread_exit_thread, METH_NOARGS, exit_doc}, - {"interrupt_main", (PyCFunction)thread_PyThread_interrupt_main, + {"interrupt_main", thread_PyThread_interrupt_main, METH_NOARGS, interrupt_doc}, - {"get_ident", (PyCFunction)thread_get_ident, + {"get_ident", thread_get_ident, METH_NOARGS, get_ident_doc}, - {"_count", (PyCFunction)thread__count, + {"_count", thread__count, METH_NOARGS, _count_doc}, {"stack_size", (PyCFunction)thread_stack_size, METH_VARARGS, stack_size_doc}, - {"_set_sentinel", (PyCFunction)thread__set_sentinel, + {"_set_sentinel", thread__set_sentinel, METH_NOARGS, _set_sentinel_doc}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c index 16aa09b04ff209..3a0c0573826692 100644 --- a/Modules/_uuidmodule.c +++ b/Modules/_uuidmodule.c @@ -10,7 +10,8 @@ static PyObject * -py_uuid_generate_time_safe(void) +py_uuid_generate_time_safe(PyObject *Py_UNUSED(context), + PyObject *Py_UNUSED(ignored)) { uuid_t uuid; #ifdef HAVE_UUID_GENERATE_TIME_SAFE @@ -30,7 +31,7 @@ py_uuid_generate_time_safe(void) static PyMethodDef uuid_methods[] = { - {"generate_time_safe", (PyCFunction) py_uuid_generate_time_safe, METH_NOARGS, NULL}, + {"generate_time_safe", py_uuid_generate_time_safe, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* sentinel */ }; diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 49d3b48e387928..634823a7a2717e 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -2171,7 +2171,7 @@ So does an unrecognized ID."); static PyObject * -interp_list_all(PyObject *self) +interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *ids, *id; PyInterpreterState *interp; @@ -2209,7 +2209,7 @@ Return a list containing the ID of every existing interpreter."); static PyObject * -interp_get_current(PyObject *self) +interp_get_current(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyInterpreterState *interp =_get_current(); if (interp == NULL) { @@ -2225,7 +2225,7 @@ Return the ID of current interpreter."); static PyObject * -interp_get_main(PyObject *self) +interp_get_main(PyObject *self, PyObject *Py_UNUSED(ignored)) { // Currently, 0 is always the main interpreter. return PyLong_FromLongLong(0); @@ -2341,7 +2341,7 @@ PyDoc_STRVAR(is_running_doc, Return whether or not the identified interpreter is running."); static PyObject * -channel_create(PyObject *self) +channel_create(PyObject *self, PyObject *Py_UNUSED(ignored)) { int64_t cid = _channel_create(&_globals.channels); if (cid < 0) { @@ -2389,7 +2389,7 @@ Close and finalize the channel. Afterward attempts to use the channel\n\ will behave as though it never existed."); static PyObject * -channel_list_all(PyObject *self) +channel_list_all(PyObject *self, PyObject *Py_UNUSED(ignored)) { int64_t count = 0; int64_t *cids = _channels_list_all(&_globals.channels, &count); @@ -2546,11 +2546,11 @@ static PyMethodDef module_functions[] = { METH_VARARGS, create_doc}, {"destroy", (PyCFunction)interp_destroy, METH_VARARGS, destroy_doc}, - {"list_all", (PyCFunction)interp_list_all, + {"list_all", interp_list_all, METH_NOARGS, list_all_doc}, - {"get_current", (PyCFunction)interp_get_current, + {"get_current", interp_get_current, METH_NOARGS, get_current_doc}, - {"get_main", (PyCFunction)interp_get_main, + {"get_main", interp_get_main, METH_NOARGS, get_main_doc}, {"is_running", (PyCFunction)interp_is_running, METH_VARARGS, is_running_doc}, @@ -2560,11 +2560,11 @@ static PyMethodDef module_functions[] = { {"is_shareable", (PyCFunction)object_is_shareable, METH_VARARGS, is_shareable_doc}, - {"channel_create", (PyCFunction)channel_create, + {"channel_create", channel_create, METH_NOARGS, channel_create_doc}, {"channel_destroy", (PyCFunction)channel_destroy, METH_VARARGS, channel_destroy_doc}, - {"channel_list_all", (PyCFunction)channel_list_all, + {"channel_list_all", channel_list_all, METH_NOARGS, channel_list_all_doc}, {"channel_send", (PyCFunction)channel_send, METH_VARARGS, channel_send_doc}, diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index 0f831c9eec722c..574cc5ee174b7b 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -39,7 +39,7 @@ _dbm_dbm_keys(dbmobject *self, PyObject *Py_UNUSED(ignored)) } PyDoc_STRVAR(_dbm_dbm_get__doc__, -"get($self, key, default=b\'\', /)\n" +"get($self, key, default=None, /)\n" "--\n" "\n" "Return the value for key if present, otherwise default."); @@ -57,7 +57,7 @@ _dbm_dbm_get(dbmobject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; const char *key; Py_ssize_clean_t key_length; - PyObject *default_value = NULL; + PyObject *default_value = Py_None; if (!_PyArg_ParseStack(args, nargs, "s#|O:get", &key, &key_length, &default_value)) { @@ -141,4 +141,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=5c858b4080a011a4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1cba297bc8d7c2c2 input=a9049054013a1b77]*/ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index f1da9f7a839fdb..2f9c2f675836b8 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -533,7 +533,7 @@ faulthandler_disable(void) } static PyObject* -faulthandler_disable_py(PyObject *self) +faulthandler_disable_py(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (!fatal_error.enabled) { Py_RETURN_FALSE; @@ -543,7 +543,7 @@ faulthandler_disable_py(PyObject *self) } static PyObject* -faulthandler_is_enabled(PyObject *self) +faulthandler_is_enabled(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyBool_FromLong(fatal_error.enabled); } @@ -718,7 +718,8 @@ faulthandler_dump_traceback_later(PyObject *self, } static PyObject* -faulthandler_cancel_dump_traceback_later_py(PyObject *self) +faulthandler_cancel_dump_traceback_later_py(PyObject *self, + PyObject *Py_UNUSED(ignored)) { cancel_dump_traceback_later(); Py_RETURN_NONE; @@ -1116,7 +1117,7 @@ stack_overflow(uintptr_t min_sp, uintptr_t max_sp, size_t *depth) } static PyObject * -faulthandler_stack_overflow(PyObject *self) +faulthandler_stack_overflow(PyObject *self, PyObject *Py_UNUSED(ignored)) { size_t depth, size; uintptr_t sp = (uintptr_t)&depth; @@ -1177,9 +1178,9 @@ static PyMethodDef module_methods[] = { (PyCFunction)faulthandler_py_enable, METH_VARARGS|METH_KEYWORDS, PyDoc_STR("enable(file=sys.stderr, all_threads=True): " "enable the fault handler")}, - {"disable", (PyCFunction)faulthandler_disable_py, METH_NOARGS, + {"disable", faulthandler_disable_py, METH_NOARGS, PyDoc_STR("disable(): disable the fault handler")}, - {"is_enabled", (PyCFunction)faulthandler_is_enabled, METH_NOARGS, + {"is_enabled", faulthandler_is_enabled, METH_NOARGS, PyDoc_STR("is_enabled()->bool: check if the handler is enabled")}, {"dump_traceback", (PyCFunction)faulthandler_dump_traceback_py, METH_VARARGS|METH_KEYWORDS, @@ -1194,7 +1195,7 @@ static PyMethodDef module_methods[] = { "or each timeout seconds if repeat is True. If exit is True, " "call _exit(1) which is not safe.")}, {"cancel_dump_traceback_later", - (PyCFunction)faulthandler_cancel_dump_traceback_later_py, METH_NOARGS, + faulthandler_cancel_dump_traceback_later_py, METH_NOARGS, PyDoc_STR("cancel_dump_traceback_later():\ncancel the previous call " "to dump_traceback_later().")}, #endif @@ -1227,7 +1228,7 @@ static PyMethodDef module_methods[] = { {"_fatal_error", faulthandler_fatal_error_py, METH_VARARGS, PyDoc_STR("_fatal_error(message): call Py_FatalError(message)")}, #ifdef FAULTHANDLER_STACK_OVERFLOW - {"_stack_overflow", (PyCFunction)faulthandler_stack_overflow, METH_NOARGS, + {"_stack_overflow", faulthandler_stack_overflow, METH_NOARGS, PyDoc_STR("_stack_overflow(): recursive call to raise a stack overflow")}, #endif #ifdef MS_WINDOWS diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index e0810c85c12be0..8a36755bfa7265 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -138,7 +138,7 @@ groupby_next(groupbyobject *gbo) } static PyObject * -groupby_reduce(groupbyobject *lz) +groupby_reduce(groupbyobject *lz, PyObject *Py_UNUSED(ignored)) { /* reduce as a 'new' call with an optional 'setstate' if groupby * has started @@ -320,7 +320,7 @@ _grouper_next(_grouperobject *igo) } static PyObject * -_grouper_reduce(_grouperobject *lz) +_grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored)) { if (((groupbyobject *)lz->parent)->currgrouper != lz) { return Py_BuildValue("N(())", _PyObject_GetBuiltin("iter")); @@ -504,7 +504,7 @@ teedataobject_dealloc(teedataobject *tdo) } static PyObject * -teedataobject_reduce(teedataobject *tdo) +teedataobject_reduce(teedataobject *tdo, PyObject *Py_UNUSED(ignored)) { int i; /* create a temporary list of already iterated values */ @@ -649,7 +649,7 @@ tee_traverse(teeobject *to, visitproc visit, void *arg) } static PyObject * -tee_copy(teeobject *to) +tee_copy(teeobject *to, PyObject *Py_UNUSED(ignored)) { teeobject *newto; @@ -676,7 +676,7 @@ tee_fromiterable(PyObject *iterable) if (it == NULL) return NULL; if (PyObject_TypeCheck(it, &tee_type)) { - to = (teeobject *)tee_copy((teeobject *)it); + to = (teeobject *)tee_copy((teeobject *)it, NULL); goto done; } @@ -726,7 +726,7 @@ tee_dealloc(teeobject *to) } static PyObject * -tee_reduce(teeobject *to) +tee_reduce(teeobject *to, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(())(Oi)", Py_TYPE(to), to->dataobj, to->index); } @@ -973,7 +973,7 @@ cycle_next(cycleobject *lz) } static PyObject * -cycle_reduce(cycleobject *lz) +cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) { /* Create a new cycle with the iterator tuple, then set the saved state */ if (lz->it == NULL) { @@ -1168,7 +1168,7 @@ dropwhile_next(dropwhileobject *lz) } static PyObject * -dropwhile_reduce(dropwhileobject *lz) +dropwhile_reduce(dropwhileobject *lz, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OO)l", Py_TYPE(lz), lz->func, lz->it, lz->start); } @@ -1332,7 +1332,7 @@ takewhile_next(takewhileobject *lz) } static PyObject * -takewhile_reduce(takewhileobject *lz) +takewhile_reduce(takewhileobject *lz, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OO)l", Py_TYPE(lz), lz->func, lz->it, lz->stop); } @@ -1558,7 +1558,7 @@ islice_next(isliceobject *lz) } static PyObject * -islice_reduce(isliceobject *lz) +islice_reduce(isliceobject *lz, PyObject *Py_UNUSED(ignored)) { /* When unpickled, generate a new object with the same bounds, * then 'setstate' with the next and count @@ -1746,7 +1746,7 @@ starmap_next(starmapobject *lz) } static PyObject * -starmap_reduce(starmapobject *lz) +starmap_reduce(starmapobject *lz, PyObject *Py_UNUSED(ignored)) { /* Just pickle the iterator */ return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it); @@ -1918,7 +1918,7 @@ chain_next(chainobject *lz) } static PyObject * -chain_reduce(chainobject *lz) +chain_reduce(chainobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->source) { /* we can't pickle function objects (itertools.from_iterable) so @@ -2242,7 +2242,7 @@ product_next(productobject *lz) } static PyObject * -product_reduce(productobject *lz) +product_reduce(productobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->stopped) { return Py_BuildValue("O(())", Py_TYPE(lz)); @@ -2569,7 +2569,7 @@ combinations_next(combinationsobject *co) } static PyObject * -combinations_reduce(combinationsobject *lz) +combinations_reduce(combinationsobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->result == NULL) { return Py_BuildValue("O(On)", Py_TYPE(lz), lz->pool, lz->r); @@ -2903,7 +2903,7 @@ cwr_next(cwrobject *co) } static PyObject * -cwr_reduce(cwrobject *lz) +cwr_reduce(cwrobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->result == NULL) { return Py_BuildValue("O(On)", Py_TYPE(lz), lz->pool, lz->r); @@ -3262,7 +3262,7 @@ permutations_next(permutationsobject *po) } static PyObject * -permutations_reduce(permutationsobject *po) +permutations_reduce(permutationsobject *po, PyObject *Py_UNUSED(ignored)) { if (po->result == NULL) { return Py_BuildValue("O(On)", Py_TYPE(po), po->pool, po->r); @@ -3514,7 +3514,7 @@ accumulate_next(accumulateobject *lz) } static PyObject * -accumulate_reduce(accumulateobject *lz) +accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->total == Py_None) { PyObject *it; @@ -3707,7 +3707,7 @@ compress_next(compressobject *lz) } static PyObject * -compress_reduce(compressobject *lz) +compress_reduce(compressobject *lz, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->data, lz->selectors); @@ -3865,7 +3865,7 @@ filterfalse_next(filterfalseobject *lz) } static PyObject * -filterfalse_reduce(filterfalseobject *lz) +filterfalse_reduce(filterfalseobject *lz, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it); } @@ -4108,7 +4108,7 @@ count_repr(countobject *lz) } static PyObject * -count_reduce(countobject *lz) +count_reduce(countobject *lz, PyObject *Py_UNUSED(ignored)) { if (lz->cnt == PY_SSIZE_T_MAX) return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->long_cnt, lz->long_step); @@ -4253,7 +4253,7 @@ repeat_repr(repeatobject *ro) } static PyObject * -repeat_len(repeatobject *ro) +repeat_len(repeatobject *ro, PyObject *Py_UNUSED(ignored)) { if (ro->cnt == -1) { PyErr_SetString(PyExc_TypeError, "len() of unsized object"); @@ -4265,7 +4265,7 @@ repeat_len(repeatobject *ro) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -repeat_reduce(repeatobject *ro) +repeat_reduce(repeatobject *ro, PyObject *Py_UNUSED(ignored)) { /* unpickle this so that a new repeat iterator is constructed with an * object, then call __setstate__ on it to set cnt @@ -4504,7 +4504,7 @@ zip_longest_next(ziplongestobject *lz) } static PyObject * -zip_longest_reduce(ziplongestobject *lz) +zip_longest_reduce(ziplongestobject *lz, PyObject *Py_UNUSED(ignored)) { /* Create a new tuple with empty sequences where appropriate to pickle. diff --git a/Modules/makesetup b/Modules/makesetup index 31faf861d1b6f9..020b19938c4866 100755 --- a/Modules/makesetup +++ b/Modules/makesetup @@ -233,7 +233,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | case $doconfig in no) cc="$cc \$(CCSHARED) \$(PY_CFLAGS) \$(PY_CPPFLAGS)";; *) - cc="$cc \$(PY_CORE_CFLAGS)";; + cc="$cc \$(PY_STDMODULE_CFLAGS)";; esac rule="$obj: $src; $cc $cpps -c $src -o $obj" echo "$rule" >>$rulesf diff --git a/Modules/nismodule.c b/Modules/nismodule.c index a9028bbfe54c6c..1a538dc3b2332d 100644 --- a/Modules/nismodule.c +++ b/Modules/nismodule.c @@ -137,7 +137,7 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval, } static PyObject * -nis_get_default_domain (PyObject *self) +nis_get_default_domain (PyObject *self, PyObject *Py_UNUSED(ignored)) { char *domain; int err; @@ -432,7 +432,7 @@ static PyMethodDef nis_methods[] = { {"maps", (PyCFunction)nis_maps, METH_VARARGS | METH_KEYWORDS, maps__doc__}, - {"get_default_domain", (PyCFunction)nis_get_default_domain, + {"get_default_domain", nis_get_default_domain, METH_NOARGS, get_default_domain__doc__}, {NULL, NULL} /* Sentinel */ diff --git a/Modules/overlapped.c b/Modules/overlapped.c index ae7cddadd02df7..69875a7f37da51 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -618,7 +618,7 @@ PyDoc_STRVAR( "Cancel overlapped operation"); static PyObject * -Overlapped_cancel(OverlappedObject *self) +Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored)) { BOOL ret = TRUE; diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index 2b98be40e308db..38e5f750d5723d 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -135,18 +135,18 @@ node2tuple(node *n, /* node to convert */ goto error; (void) addelem(result, 1, w); - if (lineno == 1) { + if (lineno) { w = PyLong_FromLong(n->n_lineno); if (w == NULL) goto error; (void) addelem(result, 2, w); } - if (col_offset == 1) { + if (col_offset) { w = PyLong_FromLong(n->n_col_offset); if (w == NULL) goto error; - (void) addelem(result, 3, w); + (void) addelem(result, 2 + lineno, w); } } else { diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index fe2968af80919a..a366d1b88b68c0 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1006,7 +1006,7 @@ devpoll_internal_close(devpollObject *self) } static PyObject* -devpoll_close(devpollObject *self) +devpoll_close(devpollObject *self, PyObject *Py_UNUSED(ignored)) { errno = devpoll_internal_close(self); if (errno < 0) { @@ -1032,7 +1032,7 @@ devpoll_get_closed(devpollObject *self) } static PyObject* -devpoll_fileno(devpollObject *self) +devpoll_fileno(devpollObject *self, PyObject *Py_UNUSED(ignored)) { if (self->fd_devpoll < 0) return devpoll_err_closed(); @@ -1327,7 +1327,7 @@ pyepoll_dealloc(pyEpoll_Object *self) } static PyObject* -pyepoll_close(pyEpoll_Object *self) +pyepoll_close(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored)) { errno = pyepoll_internal_close(self); if (errno < 0) { @@ -1353,7 +1353,7 @@ pyepoll_get_closed(pyEpoll_Object *self) } static PyObject* -pyepoll_fileno(pyEpoll_Object *self) +pyepoll_fileno(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored)) { if (self->epfd < 0) return pyepoll_err_closed(); @@ -2053,7 +2053,7 @@ kqueue_queue_dealloc(kqueue_queue_Object *self) } static PyObject* -kqueue_queue_close(kqueue_queue_Object *self) +kqueue_queue_close(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored)) { errno = kqueue_queue_internal_close(self); if (errno < 0) { @@ -2079,7 +2079,7 @@ kqueue_queue_get_closed(kqueue_queue_Object *self) } static PyObject* -kqueue_queue_fileno(kqueue_queue_Object *self) +kqueue_queue_fileno(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored)) { if (self->kqfd < 0) return kqueue_queue_err_closed(); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 7916160143840c..35fd87e2d1e711 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -819,7 +819,6 @@ iterable_to_sigset(PyObject *iterable, sigset_t *mask) int result = -1; PyObject *iterator, *item; long signum; - int err; sigemptyset(mask); @@ -841,11 +840,14 @@ iterable_to_sigset(PyObject *iterable, sigset_t *mask) Py_DECREF(item); if (signum == -1 && PyErr_Occurred()) goto error; - if (0 < signum && signum < NSIG) - err = sigaddset(mask, (int)signum); - else - err = 1; - if (err) { + if (0 < signum && signum < NSIG) { + /* bpo-33329: ignore sigaddset() return value as it can fail + * for some reserved signals, but we want the `range(1, NSIG)` + * idiom to allow selecting all valid signals. + */ + (void) sigaddset(mask, (int)signum); + } + else { PyErr_Format(PyExc_ValueError, "signal number %ld out of range", signum); goto error; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index c7a07512026b36..30001754fe576b 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2504,7 +2504,7 @@ sock_accept_impl(PySocketSockObject *s, void *data) /* s._accept() -> (fd, address) */ static PyObject * -sock_accept(PySocketSockObject *s) +sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { sock_addr_t addrbuf; SOCKET_T newfd; @@ -2605,7 +2605,7 @@ setblocking(False) is equivalent to settimeout(0.0)."); False if it is in non-blocking mode. */ static PyObject * -sock_getblocking(PySocketSockObject *s) +sock_getblocking(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { if (s->sock_timeout) { Py_RETURN_TRUE; @@ -2717,7 +2717,7 @@ Setting a timeout of zero is the same as setblocking(0)."); /* s.gettimeout() method. Returns the timeout associated with a socket. */ static PyObject * -sock_gettimeout(PySocketSockObject *s) +sock_gettimeout(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { if (s->sock_timeout < 0) { Py_RETURN_NONE; @@ -2930,7 +2930,7 @@ sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])"); will surely fail. */ static PyObject * -sock_close(PySocketSockObject *s) +sock_close(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { SOCKET_T fd; int res; @@ -2961,7 +2961,7 @@ PyDoc_STRVAR(sock_close_doc, Close the socket. It cannot be used after this call."); static PyObject * -sock_detach(PySocketSockObject *s) +sock_detach(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { SOCKET_T fd = s->sock_fd; s->sock_fd = INVALID_SOCKET; @@ -3117,7 +3117,7 @@ instead of raising an exception when an error occurs."); /* s.fileno() method */ static PyObject * -sock_fileno(PySocketSockObject *s) +sock_fileno(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSocket_t(s->sock_fd); } @@ -3131,7 +3131,7 @@ Return the integer file descriptor of the socket."); /* s.getsockname() method */ static PyObject * -sock_getsockname(PySocketSockObject *s) +sock_getsockname(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { sock_addr_t addrbuf; int res; @@ -3160,7 +3160,7 @@ info is a pair (hostaddr, port)."); /* s.getpeername() method */ static PyObject * -sock_getpeername(PySocketSockObject *s) +sock_getpeername(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { sock_addr_t addrbuf; int res; @@ -6390,7 +6390,7 @@ Get host and port for a sockaddr."); /* Python API to getting and setting the default timeout value. */ static PyObject * -socket_getdefaulttimeout(PyObject *self) +socket_getdefaulttimeout(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (defaulttimeout < 0) { Py_RETURN_NONE; @@ -6639,7 +6639,7 @@ static PyMethodDef socket_methods[] = { METH_VARARGS | METH_KEYWORDS, getaddrinfo_doc}, {"getnameinfo", socket_getnameinfo, METH_VARARGS, getnameinfo_doc}, - {"getdefaulttimeout", (PyCFunction)socket_getdefaulttimeout, + {"getdefaulttimeout", socket_getdefaulttimeout, METH_NOARGS, getdefaulttimeout_doc}, {"setdefaulttimeout", socket_setdefaulttimeout, METH_O, setdefaulttimeout_doc}, diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 692b7be7392455..753ee8ef3a4126 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1940,7 +1940,7 @@ PyDoc_STRVAR(alloc_doc, Return the number of bytes actually allocated."); static PyObject * -bytearray_alloc(PyByteArrayObject *self) +bytearray_alloc(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(self->ob_alloc); } @@ -2018,7 +2018,7 @@ Create a string of hexadecimal numbers from a bytearray object.\n\ Example: bytearray([0xb9, 0x01, 0xef]).hex() -> 'b901ef'."); static PyObject * -bytearray_hex(PyBytesObject *self) +bytearray_hex(PyBytesObject *self, PyObject *Py_UNUSED(ignored)) { char* argbuf = PyByteArray_AS_STRING(self); Py_ssize_t arglen = PyByteArray_GET_SIZE(self); @@ -2136,7 +2136,7 @@ bytearray_methods[] = { BYTEARRAY_REDUCE_EX_METHODDEF BYTEARRAY_SIZEOF_METHODDEF BYTEARRAY_APPEND_METHODDEF - {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, + {"capitalize", stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, _Py_center__doc__}, BYTEARRAY_CLEAR_METHODDEF @@ -2155,25 +2155,25 @@ bytearray_methods[] = { {"hex", (PyCFunction)bytearray_hex, METH_NOARGS, hex__doc__}, {"index", (PyCFunction)bytearray_index, METH_VARARGS, _Py_index__doc__}, BYTEARRAY_INSERT_METHODDEF - {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, + {"isalnum", stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, - {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, + {"isalpha", stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, - {"isascii", (PyCFunction)stringlib_isascii, METH_NOARGS, + {"isascii", stringlib_isascii, METH_NOARGS, _Py_isascii__doc__}, - {"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS, + {"isdigit", stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, - {"islower", (PyCFunction)stringlib_islower, METH_NOARGS, + {"islower", stringlib_islower, METH_NOARGS, _Py_islower__doc__}, - {"isspace", (PyCFunction)stringlib_isspace, METH_NOARGS, + {"isspace", stringlib_isspace, METH_NOARGS, _Py_isspace__doc__}, - {"istitle", (PyCFunction)stringlib_istitle, METH_NOARGS, + {"istitle", stringlib_istitle, METH_NOARGS, _Py_istitle__doc__}, - {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, + {"isupper", stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, BYTEARRAY_JOIN_METHODDEF {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, _Py_ljust__doc__}, - {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, + {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, BYTEARRAY_LSTRIP_METHODDEF BYTEARRAY_MAKETRANS_METHODDEF BYTEARRAY_PARTITION_METHODDEF @@ -2192,11 +2192,11 @@ bytearray_methods[] = { {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS , _Py_startswith__doc__}, BYTEARRAY_STRIP_METHODDEF - {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, + {"swapcase", stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, - {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__}, + {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, BYTEARRAY_TRANSLATE_METHODDEF - {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, + {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, _Py_zfill__doc__}, {NULL} }; @@ -2324,7 +2324,7 @@ bytearrayiter_next(bytesiterobject *it) } static PyObject * -bytearrayiter_length_hint(bytesiterobject *it) +bytearrayiter_length_hint(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) { @@ -2340,7 +2340,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -bytearrayiter_reduce(bytesiterobject *it) +bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index c358756bfea8e6..f5bd5fba719969 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2422,7 +2422,7 @@ Create a string of hexadecimal numbers from a bytes object.\n\ Example: b'\\xb9\\x01\\xef'.hex() -> 'b901ef'."); static PyObject * -bytes_hex(PyBytesObject *self) +bytes_hex(PyBytesObject *self, PyObject *Py_UNUSED(ignored)) { char* argbuf = PyBytes_AS_STRING(self); Py_ssize_t arglen = PyBytes_GET_SIZE(self); @@ -2430,7 +2430,7 @@ bytes_hex(PyBytesObject *self) } static PyObject * -bytes_getnewargs(PyBytesObject *v) +bytes_getnewargs(PyBytesObject *v, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("(y#)", v->ob_sval, Py_SIZE(v)); } @@ -2439,7 +2439,7 @@ bytes_getnewargs(PyBytesObject *v) static PyMethodDef bytes_methods[] = { {"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS}, - {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, + {"capitalize", stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, _Py_center__doc__}, @@ -2455,25 +2455,25 @@ bytes_methods[] = { BYTES_FROMHEX_METHODDEF {"hex", (PyCFunction)bytes_hex, METH_NOARGS, hex__doc__}, {"index", (PyCFunction)bytes_index, METH_VARARGS, _Py_index__doc__}, - {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, + {"isalnum", stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, - {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, + {"isalpha", stringlib_isalpha, METH_NOARGS, _Py_isalpha__doc__}, - {"isascii", (PyCFunction)stringlib_isascii, METH_NOARGS, + {"isascii", stringlib_isascii, METH_NOARGS, _Py_isascii__doc__}, - {"isdigit", (PyCFunction)stringlib_isdigit, METH_NOARGS, + {"isdigit", stringlib_isdigit, METH_NOARGS, _Py_isdigit__doc__}, - {"islower", (PyCFunction)stringlib_islower, METH_NOARGS, + {"islower", stringlib_islower, METH_NOARGS, _Py_islower__doc__}, - {"isspace", (PyCFunction)stringlib_isspace, METH_NOARGS, + {"isspace", stringlib_isspace, METH_NOARGS, _Py_isspace__doc__}, - {"istitle", (PyCFunction)stringlib_istitle, METH_NOARGS, + {"istitle", stringlib_istitle, METH_NOARGS, _Py_istitle__doc__}, - {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, + {"isupper", stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, BYTES_JOIN_METHODDEF {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, _Py_ljust__doc__}, - {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, + {"lower", stringlib_lower, METH_NOARGS, _Py_lower__doc__}, BYTES_LSTRIP_METHODDEF BYTES_MAKETRANS_METHODDEF BYTES_PARTITION_METHODDEF @@ -2489,11 +2489,11 @@ bytes_methods[] = { {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS, _Py_startswith__doc__}, BYTES_STRIP_METHODDEF - {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, + {"swapcase", stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, - {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__}, + {"title", stringlib_title, METH_NOARGS, _Py_title__doc__}, BYTES_TRANSLATE_METHODDEF - {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, + {"upper", stringlib_upper, METH_NOARGS, _Py_upper__doc__}, {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, _Py_zfill__doc__}, {NULL, NULL} /* sentinel */ }; @@ -3037,7 +3037,7 @@ striter_next(striterobject *it) } static PyObject * -striter_len(striterobject *it) +striter_len(striterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -3049,7 +3049,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -striter_reduce(striterobject *it) +striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), diff --git a/Objects/classobject.c b/Objects/classobject.c index 3dc23b796c2c16..095b0cad2b5c57 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -73,7 +73,7 @@ PyMethod_New(PyObject *func, PyObject *self) } static PyObject * -method_reduce(PyMethodObject *im) +method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) { PyObject *self = PyMethod_GET_SELF(im); PyObject *func = PyMethod_GET_FUNCTION(im); diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 0509b8e6400fb8..aa373a075d7dbf 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -488,14 +488,21 @@ _PyCode_ConstantKey(PyObject *op) { PyObject *key; - /* Py_None and Py_Ellipsis are singleton */ + /* Py_None and Py_Ellipsis are singletons. */ if (op == Py_None || op == Py_Ellipsis || PyLong_CheckExact(op) - || PyBool_Check(op) - || PyBytes_CheckExact(op) || PyUnicode_CheckExact(op) /* code_richcompare() uses _PyCode_ConstantKey() internally */ - || PyCode_Check(op)) { + || PyCode_Check(op)) + { + /* Objects of these types are always different from object of other + * type and from tuples. */ + Py_INCREF(op); + key = op; + } + else if (PyBool_Check(op) || PyBytes_CheckExact(op)) { + /* Make booleans different from integers 0 and 1. + * Avoid BytesWarning from comparing bytes with strings. */ key = PyTuple_Pack(2, Py_TYPE(op), op); } else if (PyFloat_CheckExact(op)) { diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 2c886c7a7685db..6e3d47b62d1937 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -695,7 +695,7 @@ complex_float(PyObject *v) } static PyObject * -complex_conjugate(PyObject *self) +complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) { Py_complex c; c = ((PyComplexObject *)self)->cval; @@ -709,7 +709,7 @@ PyDoc_STRVAR(complex_conjugate_doc, "Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); static PyObject * -complex_getnewargs(PyComplexObject *v) +complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored)) { Py_complex c = v->cval; return Py_BuildValue("(dd)", c.real, c.imag); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 60140394029965..dfad1ecda3ca3c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -448,7 +448,7 @@ descr_get_qualname(PyDescrObject *descr) } static PyObject * -descr_reduce(PyDescrObject *descr) +descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { PyObject *builtins; PyObject *getattr; @@ -868,28 +868,28 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *args) } static PyObject * -mappingproxy_keys(mappingproxyobject *pp) +mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(keys); return _PyObject_CallMethodId(pp->mapping, &PyId_keys, NULL); } static PyObject * -mappingproxy_values(mappingproxyobject *pp) +mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(values); return _PyObject_CallMethodId(pp->mapping, &PyId_values, NULL); } static PyObject * -mappingproxy_items(mappingproxyobject *pp) +mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(items); return _PyObject_CallMethodId(pp->mapping, &PyId_items, NULL); } static PyObject * -mappingproxy_copy(mappingproxyobject *pp) +mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(copy); return _PyObject_CallMethodId(pp->mapping, &PyId_copy, NULL); @@ -1086,7 +1086,7 @@ wrapper_repr(wrapperobject *wp) } static PyObject * -wrapper_reduce(wrapperobject *wp) +wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { PyObject *builtins; PyObject *getattr; diff --git a/Objects/dict-common.h b/Objects/dict-common.h index 3e524686b4400d..71d6b0274420b8 100644 --- a/Objects/dict-common.h +++ b/Objects/dict-common.h @@ -58,15 +58,8 @@ struct _dictkeysobject { - 4 bytes if dk_size <= 0xffffffff (int32_t*) - 8 bytes otherwise (int64_t*) - Dynamically sized, 8 is minimum. */ - union { - int8_t as_1[8]; - int16_t as_2[4]; - int32_t as_4[2]; -#if SIZEOF_VOID_P > 4 - int64_t as_8[1]; -#endif - } dk_indices; + Dynamically sized, SIZEOF_VOID_P is minimum. */ + char dk_indices[]; /* char is required to avoid strict aliasing. */ /* "PyDictKeyEntry dk_entries[dk_usable];" array follows: see the DK_ENTRIES() macro */ diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 01d913bfce4f84..40d7d8af6ec224 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -298,7 +298,7 @@ PyDict_Fini(void) 2 : sizeof(int32_t)) #endif #define DK_ENTRIES(dk) \ - ((PyDictKeyEntry*)(&(dk)->dk_indices.as_1[DK_SIZE(dk) * DK_IXSIZE(dk)])) + ((PyDictKeyEntry*)(&((int8_t*)((dk)->dk_indices))[DK_SIZE(dk) * DK_IXSIZE(dk)])) #define DK_DEBUG_INCREF _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA #define DK_DEBUG_DECREF _Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA @@ -316,21 +316,21 @@ dk_get_index(PyDictKeysObject *keys, Py_ssize_t i) Py_ssize_t ix; if (s <= 0xff) { - int8_t *indices = keys->dk_indices.as_1; + int8_t *indices = (int8_t*)(keys->dk_indices); ix = indices[i]; } else if (s <= 0xffff) { - int16_t *indices = keys->dk_indices.as_2; + int16_t *indices = (int16_t*)(keys->dk_indices); ix = indices[i]; } #if SIZEOF_VOID_P > 4 else if (s > 0xffffffff) { - int64_t *indices = keys->dk_indices.as_8; + int64_t *indices = (int64_t*)(keys->dk_indices); ix = indices[i]; } #endif else { - int32_t *indices = keys->dk_indices.as_4; + int32_t *indices = (int32_t*)(keys->dk_indices); ix = indices[i]; } assert(ix >= DKIX_DUMMY); @@ -346,23 +346,23 @@ dk_set_index(PyDictKeysObject *keys, Py_ssize_t i, Py_ssize_t ix) assert(ix >= DKIX_DUMMY); if (s <= 0xff) { - int8_t *indices = keys->dk_indices.as_1; + int8_t *indices = (int8_t*)(keys->dk_indices); assert(ix <= 0x7f); indices[i] = (char)ix; } else if (s <= 0xffff) { - int16_t *indices = keys->dk_indices.as_2; + int16_t *indices = (int16_t*)(keys->dk_indices); assert(ix <= 0x7fff); indices[i] = (int16_t)ix; } #if SIZEOF_VOID_P > 4 else if (s > 0xffffffff) { - int64_t *indices = keys->dk_indices.as_8; + int64_t *indices = (int64_t*)(keys->dk_indices); indices[i] = ix; } #endif else { - int32_t *indices = keys->dk_indices.as_4; + int32_t *indices = (int32_t*)(keys->dk_indices); assert(ix <= 0x7fffffff); indices[i] = (int32_t)ix; } @@ -421,8 +421,8 @@ static PyDictKeysObject empty_keys_struct = { lookdict_split, /* dk_lookup */ 0, /* dk_usable (immutable) */ 0, /* dk_nentries */ - .dk_indices = { .as_1 = {DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, - DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY}}, + {DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, + DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY, DKIX_EMPTY}, /* dk_indices */ }; static PyObject *empty_values[1] = { NULL }; @@ -530,7 +530,6 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) } else { dk = PyObject_MALLOC(sizeof(PyDictKeysObject) - - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + es * size + sizeof(PyDictKeyEntry) * usable); if (dk == NULL) { @@ -543,7 +542,7 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) dk->dk_usable = usable; dk->dk_lookup = lookdict_unicode_nodummy; dk->dk_nentries = 0; - memset(&dk->dk_indices.as_1[0], 0xff, es * size); + memset(&dk->dk_indices[0], 0xff, es * size); memset(DK_ENTRIES(dk), 0, sizeof(PyDictKeyEntry) * usable); return dk; } @@ -2512,7 +2511,7 @@ _PyDict_MergeEx(PyObject *a, PyObject *b, int override) } static PyObject * -dict_copy(PyDictObject *mp) +dict_copy(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { return PyDict_Copy((PyObject*)mp); } @@ -2574,7 +2573,7 @@ PyDict_Copy(PyObject *o) (3) if 'mp' is non-compact ('del' operation does not resize dicts), do fast-copy only if it has at most 1/3 non-used keys. - The last condition (3) is important to guard against a pathalogical + The last condition (3) is important to guard against a pathological case when a large dict is almost emptied with multiple del/pop operations and copied after that. In cases like this, we defer to PyDict_Merge, which produces a compacted copy. @@ -2875,7 +2874,7 @@ dict_setdefault_impl(PyDictObject *self, PyObject *key, } static PyObject * -dict_clear(PyDictObject *mp) +dict_clear(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { PyDict_Clear((PyObject *)mp); Py_RETURN_NONE; @@ -2893,7 +2892,7 @@ dict_pop(PyDictObject *mp, PyObject *args) } static PyObject * -dict_popitem(PyDictObject *mp) +dict_popitem(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { Py_ssize_t i, j; PyDictKeyEntry *ep0, *ep; @@ -3007,7 +3006,6 @@ _PyDict_SizeOf(PyDictObject *mp) in the type object. */ if (mp->ma_keys->dk_refcnt == 1) res += (sizeof(PyDictKeysObject) - - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + DK_IXSIZE(mp->ma_keys) * size + sizeof(PyDictKeyEntry) * usable); return res; @@ -3017,13 +3015,12 @@ Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys) { return (sizeof(PyDictKeysObject) - - Py_MEMBER_SIZE(PyDictKeysObject, dk_indices) + DK_IXSIZE(keys) * DK_SIZE(keys) + USABLE_FRACTION(DK_SIZE(keys)) * sizeof(PyDictKeyEntry)); } static PyObject * -dict_sizeof(PyDictObject *mp) +dict_sizeof(PyDictObject *mp, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(_PyDict_SizeOf(mp)); } @@ -3054,9 +3051,9 @@ PyDoc_STRVAR(copy__doc__, "D.copy() -> a shallow copy of D"); /* Forward */ -static PyObject *dictkeys_new(PyObject *); -static PyObject *dictitems_new(PyObject *); -static PyObject *dictvalues_new(PyObject *); +static PyObject *dictkeys_new(PyObject *, PyObject *); +static PyObject *dictitems_new(PyObject *, PyObject *); +static PyObject *dictvalues_new(PyObject *, PyObject *); PyDoc_STRVAR(keys__doc__, "D.keys() -> a set-like object providing a view on D's keys"); @@ -3077,11 +3074,11 @@ static PyMethodDef mapp_methods[] = { pop__doc__}, {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, popitem__doc__}, - {"keys", (PyCFunction)dictkeys_new, METH_NOARGS, + {"keys", dictkeys_new, METH_NOARGS, keys__doc__}, - {"items", (PyCFunction)dictitems_new, METH_NOARGS, + {"items", dictitems_new, METH_NOARGS, items__doc__}, - {"values", (PyCFunction)dictvalues_new, METH_NOARGS, + {"values", dictvalues_new, METH_NOARGS, values__doc__}, {"update", (PyCFunction)dict_update, METH_VARARGS | METH_KEYWORDS, update__doc__}, @@ -3364,7 +3361,7 @@ dictiter_traverse(dictiterobject *di, visitproc visit, void *arg) } static PyObject * -dictiter_len(dictiterobject *di) +dictiter_len(dictiterobject *di, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used) @@ -3376,7 +3373,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -dictiter_reduce(dictiterobject *di); +dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -3655,7 +3652,7 @@ PyTypeObject PyDictIterItem_Type = { static PyObject * -dictiter_reduce(dictiterobject *di) +dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) { PyObject *list; dictiterobject tmp; @@ -4095,7 +4092,7 @@ PyTypeObject PyDictKeys_Type = { }; static PyObject * -dictkeys_new(PyObject *dict) +dictkeys_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictKeys_Type); } @@ -4185,7 +4182,7 @@ PyTypeObject PyDictItems_Type = { }; static PyObject * -dictitems_new(PyObject *dict) +dictitems_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictItems_Type); } @@ -4250,7 +4247,7 @@ PyTypeObject PyDictValues_Type = { }; static PyObject * -dictvalues_new(PyObject *dict) +dictvalues_new(PyObject *dict, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(dict, &PyDictValues_Type); } diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 4d0af14008b939..d993a5063fdf60 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -189,7 +189,7 @@ enum_next(enumobject *en) } static PyObject * -enum_reduce(enumobject *en) +enum_reduce(enumobject *en, PyObject *Py_UNUSED(ignored)) { if (en->en_longindex != NULL) return Py_BuildValue("O(OO)", Py_TYPE(en), en->en_sit, en->en_longindex); @@ -349,7 +349,7 @@ reversed_next(reversedobject *ro) } static PyObject * -reversed_len(reversedobject *ro) +reversed_len(reversedobject *ro, PyObject *Py_UNUSED(ignored)) { Py_ssize_t position, seqsize; @@ -365,7 +365,7 @@ reversed_len(reversedobject *ro) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -reversed_reduce(reversedobject *ro) +reversed_reduce(reversedobject *ro, PyObject *Py_UNUSED(ignored)) { if (ro->seq) return Py_BuildValue("O(O)n", Py_TYPE(ro), ro->seq, ro->index); diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 2cce40f884442a..bfc818f7b4ca61 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -126,7 +126,7 @@ BaseException_repr(PyBaseExceptionObject *self) /* Pickling support */ static PyObject * -BaseException_reduce(PyBaseExceptionObject *self) +BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored)) { if (self->args && self->dict) return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict); @@ -713,7 +713,7 @@ ImportError_getstate(PyImportErrorObject *self) /* Pickling support */ static PyObject * -ImportError_reduce(PyImportErrorObject *self) +ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *res; PyObject *args; @@ -1123,7 +1123,7 @@ OSError_str(PyOSErrorObject *self) } static PyObject * -OSError_reduce(PyOSErrorObject *self) +OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored)) { PyObject *args = self->args; PyObject *res = NULL, *tmp; diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 0f71944d526ec8..db788a9eccbbed 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -398,7 +398,7 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) } static PyObject * -stdprinter_fileno(PyStdPrinter_Object *self) +stdprinter_fileno(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong((long) self->fd); } @@ -411,13 +411,13 @@ stdprinter_repr(PyStdPrinter_Object *self) } static PyObject * -stdprinter_noop(PyStdPrinter_Object *self) +stdprinter_noop(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { Py_RETURN_NONE; } static PyObject * -stdprinter_isatty(PyStdPrinter_Object *self) +stdprinter_isatty(PyStdPrinter_Object *self, PyObject *Py_UNUSED(ignored)) { long res; if (self->fd < 0) { diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 864a8f977ea398..64ee386ddf9654 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -297,7 +297,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) if (delta_iblock > 0) { f->f_iblock -= delta_iblock; PyTryBlock *b = &f->f_blockstack[f->f_iblock]; - delta += (f->f_stacktop - f->f_valuestack) - b->b_level; + delta += (int)(f->f_stacktop - f->f_valuestack) - b->b_level; if (b->b_type == SETUP_FINALLY && code[b->b_handler] == WITH_CLEANUP_START) { @@ -500,7 +500,7 @@ frame_tp_clear(PyFrameObject *f) } static PyObject * -frame_clear(PyFrameObject *f) +frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { if (f->f_executing) { PyErr_SetString(PyExc_RuntimeError, @@ -519,7 +519,7 @@ PyDoc_STRVAR(clear__doc__, "F.clear(): clear most references held by the frame"); static PyObject * -frame_sizeof(PyFrameObject *f) +frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res, extras, ncells, nfrees; diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 252169acbfdb8f..5f5ebfc8c0e5cd 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -78,7 +78,7 @@ iter_iternext(PyObject *iterator) } static PyObject * -iter_len(seqiterobject *it) +iter_len(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t seqsize, len; @@ -101,7 +101,7 @@ iter_len(seqiterobject *it) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -iter_reduce(seqiterobject *it) +iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), @@ -240,7 +240,7 @@ calliter_iternext(calliterobject *it) } static PyObject * -calliter_reduce(calliterobject *it) +calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_callable != NULL && it->it_sentinel != NULL) return Py_BuildValue("N(OO)", _PyObject_GetBuiltin("iter"), diff --git a/Objects/listobject.c b/Objects/listobject.c index c8ffeff09368de..4108f502023ad0 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2983,9 +2983,9 @@ typedef struct { static void listiter_dealloc(listiterobject *); static int listiter_traverse(listiterobject *, visitproc, void *); static PyObject *listiter_next(listiterobject *); -static PyObject *listiter_len(listiterobject *); +static PyObject *listiter_len(listiterobject *, PyObject *); static PyObject *listiter_reduce_general(void *_it, int forward); -static PyObject *listiter_reduce(listiterobject *); +static PyObject *listiter_reduce(listiterobject *, PyObject *); static PyObject *listiter_setstate(listiterobject *, PyObject *state); PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); @@ -3092,7 +3092,7 @@ listiter_next(listiterobject *it) } static PyObject * -listiter_len(listiterobject *it) +listiter_len(listiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len; if (it->it_seq) { @@ -3104,7 +3104,7 @@ listiter_len(listiterobject *it) } static PyObject * -listiter_reduce(listiterobject *it) +listiter_reduce(listiterobject *it, PyObject *Py_UNUSED(ignored)) { return listiter_reduce_general(it, 1); } @@ -3136,8 +3136,8 @@ typedef struct { static void listreviter_dealloc(listreviterobject *); static int listreviter_traverse(listreviterobject *, visitproc, void *); static PyObject *listreviter_next(listreviterobject *); -static PyObject *listreviter_len(listreviterobject *); -static PyObject *listreviter_reduce(listreviterobject *); +static PyObject *listreviter_len(listreviterobject *, PyObject *); +static PyObject *listreviter_reduce(listreviterobject *, PyObject *); static PyObject *listreviter_setstate(listreviterobject *, PyObject *); static PyMethodDef listreviter_methods[] = { @@ -3246,7 +3246,7 @@ listreviter_next(listreviterobject *it) } static PyObject * -listreviter_len(listreviterobject *it) +listreviter_len(listreviterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = it->it_index + 1; if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len) @@ -3255,7 +3255,7 @@ listreviter_len(listreviterobject *it) } static PyObject * -listreviter_reduce(listreviterobject *it) +listreviter_reduce(listreviterobject *it, PyObject *Py_UNUSED(ignored)) { return listiter_reduce_general(it, 0); } diff --git a/Objects/longobject.c b/Objects/longobject.c index 269d6cdea590ff..1c5ab3b3fc76e6 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2537,7 +2537,7 @@ PyLong_FromUnicodeObject(PyObject *u, int base) /* forward */ static PyLongObject *x_divrem (PyLongObject *, PyLongObject *, PyLongObject **); -static PyObject *long_long(PyObject *v); +static PyObject *long_long(PyObject *v, PyObject *Py_UNUSED(ignored)); /* Int division with remainder, top-level routine */ @@ -2557,7 +2557,7 @@ long_divrem(PyLongObject *a, PyLongObject *b, (size_a == size_b && a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) { /* |a| < |b|. */ - *prem = (PyLongObject *)long_long((PyObject *)a); + *prem = (PyLongObject *)long_long((PyObject *)a, NULL); if (*prem == NULL) { return -1; } @@ -4242,7 +4242,7 @@ long_abs(PyLongObject *v) if (Py_SIZE(v) < 0) return long_neg(v); else - return long_long((PyObject *)v); + return long_long((PyObject *)v, NULL); } static int @@ -4554,7 +4554,7 @@ long_or(PyObject *a, PyObject *b) } static PyObject * -long_long(PyObject *v) +long_long(PyObject *v, PyObject *Py_UNUSED(ignored)) { if (PyLong_CheckExact(v)) Py_INCREF(v); @@ -5028,7 +5028,7 @@ long_round(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "|O", &o_ndigits)) return NULL; if (o_ndigits == NULL) - return long_long(self); + return long_long(self, NULL); ndigits = PyNumber_Index(o_ndigits); if (ndigits == NULL) @@ -5037,7 +5037,7 @@ long_round(PyObject *self, PyObject *args) /* if ndigits >= 0 then no rounding is necessary; return self unchanged */ if (Py_SIZE(ndigits) >= 0) { Py_DECREF(ndigits); - return long_long(self); + return long_long(self, NULL); } /* result = self - divmod_near(self, 10 ** -ndigits)[1] */ @@ -5279,7 +5279,7 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, } static PyMethodDef long_methods[] = { - {"conjugate", (PyCFunction)long_long, METH_NOARGS, + {"conjugate", long_long, METH_NOARGS, "Returns self, the complex conjugate of any int."}, INT_BIT_LENGTH_METHODDEF #if 0 @@ -5288,11 +5288,11 @@ static PyMethodDef long_methods[] = { #endif INT_TO_BYTES_METHODDEF INT_FROM_BYTES_METHODDEF - {"__trunc__", (PyCFunction)long_long, METH_NOARGS, + {"__trunc__", long_long, METH_NOARGS, "Truncating an Integral returns itself."}, - {"__floor__", (PyCFunction)long_long, METH_NOARGS, + {"__floor__", long_long, METH_NOARGS, "Flooring an Integral returns itself."}, - {"__ceil__", (PyCFunction)long_long, METH_NOARGS, + {"__ceil__", long_long, METH_NOARGS, "Ceiling of an Integral returns itself."}, {"__round__", (PyCFunction)long_round, METH_VARARGS, "Rounding an Integral returns itself.\n" diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 2cf314660d00c2..9606768a48c5e0 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -101,7 +101,7 @@ meth_dealloc(PyCFunctionObject *m) } static PyObject * -meth_reduce(PyCFunctionObject *m) +meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) { PyObject *builtins; PyObject *getattr; diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 8fb368e41474a8..5fad4474be0f7c 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -603,8 +603,9 @@ _PyModule_ClearDict(PyObject *d) else PyErr_Clear(); } - if (PyDict_SetItem(d, key, Py_None) != 0) - PyErr_Clear(); + if (PyDict_SetItem(d, key, Py_None) != 0) { + PyErr_WriteUnraisable(NULL); + } } } } @@ -623,8 +624,9 @@ _PyModule_ClearDict(PyObject *d) else PyErr_Clear(); } - if (PyDict_SetItem(d, key, Py_None) != 0) - PyErr_Clear(); + if (PyDict_SetItem(d, key, Py_None) != 0) { + PyErr_WriteUnraisable(NULL); + } } } } diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index e5698e6378de60..a6c941afc0ade3 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -173,7 +173,7 @@ namespace_richcompare(PyObject *self, PyObject *other, int op) PyDoc_STRVAR(namespace_reduce__doc__, "Return state information for pickling"); static PyObject * -namespace_reduce(_PyNamespaceObject *ns) +namespace_reduce(_PyNamespaceObject *ns, PyObject *Py_UNUSED(ignored)) { PyObject *result, *args = PyTuple_New(0); diff --git a/Objects/object.c b/Objects/object.c index 220aa90bf59c5b..6532c3b287e743 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1619,13 +1619,13 @@ NotImplemented_repr(PyObject *op) } static PyObject * -NotImplemented_reduce(PyObject *op) +NotImplemented_reduce(PyObject *op, PyObject *Py_UNUSED(ignored)) { return PyUnicode_FromString("NotImplemented"); } static PyMethodDef notimplemented_methods[] = { - {"__reduce__", (PyCFunction)NotImplemented_reduce, METH_NOARGS, NULL}, + {"__reduce__", NotImplemented_reduce, METH_NOARGS, NULL}, {NULL, NULL} }; diff --git a/Objects/odictobject.c b/Objects/odictobject.c index ac97f52179e35c..2040715a3a39ac 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -884,7 +884,7 @@ OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value) PyDoc_STRVAR(odict_sizeof__doc__, ""); static PyObject * -odict_sizeof(PyODictObject *od) +odict_sizeof(PyODictObject *od, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res = _PyDict_SizeOf((PyDictObject *)od); res += sizeof(_ODictNode *) * _odict_FAST_SIZE(od); /* od_fast_nodes */ @@ -899,7 +899,7 @@ odict_sizeof(PyODictObject *od) PyDoc_STRVAR(odict_reduce__doc__, "Return state information for pickling"); static PyObject * -odict_reduce(register PyODictObject *od) +odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(__dict__); _Py_IDENTIFIER(items); @@ -1143,21 +1143,21 @@ OrderedDict_popitem_impl(PyODictObject *self, int last) /* MutableMapping.keys() does not have a docstring. */ PyDoc_STRVAR(odict_keys__doc__, ""); -static PyObject * odictkeys_new(PyObject *od); /* forward */ +static PyObject * odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* values() */ /* MutableMapping.values() does not have a docstring. */ PyDoc_STRVAR(odict_values__doc__, ""); -static PyObject * odictvalues_new(PyObject *od); /* forward */ +static PyObject * odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* items() */ /* MutableMapping.items() does not have a docstring. */ PyDoc_STRVAR(odict_items__doc__, ""); -static PyObject * odictitems_new(PyObject *od); /* forward */ +static PyObject * odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)); /* forward */ /* update() */ @@ -1175,7 +1175,7 @@ PyDoc_STRVAR(odict_clear__doc__, "od.clear() -> None. Remove all items from od."); static PyObject * -odict_clear(register PyODictObject *od) +odict_clear(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { PyDict_Clear((PyObject *)od); _odict_clear_nodes(od); @@ -1193,7 +1193,7 @@ static int _PyODict_SetItem_KnownHash(PyObject *, PyObject *, PyObject *, PyDoc_STRVAR(odict_copy__doc__, "od.copy() -> a shallow copy of od"); static PyObject * -odict_copy(register PyODictObject *od) +odict_copy(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { _ODictNode *node; PyObject *od_copy; @@ -1252,7 +1252,7 @@ PyDoc_STRVAR(odict_reversed__doc__, "od.__reversed__() <==> reversed(od)"); static PyObject * odictiter_new(PyODictObject *, int); static PyObject * -odict_reversed(PyODictObject *od) +odict_reversed(PyODictObject *od, PyObject *Py_UNUSED(ignored)) { return odictiter_new(od, _odict_ITER_KEYS|_odict_ITER_REVERSED); } @@ -1322,11 +1322,11 @@ static PyMethodDef odict_methods[] = { {"pop", (PyCFunction)odict_pop, METH_VARARGS | METH_KEYWORDS, odict_pop__doc__}, ORDEREDDICT_POPITEM_METHODDEF - {"keys", (PyCFunction)odictkeys_new, METH_NOARGS, + {"keys", odictkeys_new, METH_NOARGS, odict_keys__doc__}, - {"values", (PyCFunction)odictvalues_new, METH_NOARGS, + {"values", odictvalues_new, METH_NOARGS, odict_values__doc__}, - {"items", (PyCFunction)odictitems_new, METH_NOARGS, + {"items", odictitems_new, METH_NOARGS, odict_items__doc__}, {"update", (PyCFunction)odict_update, METH_VARARGS | METH_KEYWORDS, odict_update__doc__}, @@ -1487,7 +1487,7 @@ odict_tp_clear(PyODictObject *od) PyObject *res; Py_CLEAR(od->od_inst_dict); Py_CLEAR(od->od_weakreflist); - res = odict_clear(od); + res = odict_clear(od, NULL); if (res == NULL) return -1; Py_DECREF(res); @@ -1956,7 +1956,7 @@ odictkeys_iter(_PyDictViewObject *dv) } static PyObject * -odictkeys_reversed(_PyDictViewObject *dv) +odictkeys_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -2005,7 +2005,7 @@ PyTypeObject PyODictKeys_Type = { }; static PyObject * -odictkeys_new(PyObject *od) +odictkeys_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictKeys_Type); } @@ -2023,7 +2023,7 @@ odictitems_iter(_PyDictViewObject *dv) } static PyObject * -odictitems_reversed(_PyDictViewObject *dv) +odictitems_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -2072,7 +2072,7 @@ PyTypeObject PyODictItems_Type = { }; static PyObject * -odictitems_new(PyObject *od) +odictitems_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictItems_Type); } @@ -2090,7 +2090,7 @@ odictvalues_iter(_PyDictViewObject *dv) } static PyObject * -odictvalues_reversed(_PyDictViewObject *dv) +odictvalues_reversed(_PyDictViewObject *dv, PyObject *Py_UNUSED(ignored)) { if (dv->dv_dict == NULL) { Py_RETURN_NONE; @@ -2139,7 +2139,7 @@ PyTypeObject PyODictValues_Type = { }; static PyObject * -odictvalues_new(PyObject *od) +odictvalues_new(PyObject *od, PyObject *Py_UNUSED(ignored)) { return _PyDictView_New(od, &PyODictValues_Type); } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index dd0e4bed537002..28a244e5371007 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -636,7 +636,7 @@ static PyNumberMethods range_as_number = { }; static PyObject * range_iter(PyObject *seq); -static PyObject * range_reverse(PyObject *seq); +static PyObject * range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)); PyDoc_STRVAR(reverse_doc, "Return a reverse iterator."); @@ -649,7 +649,7 @@ PyDoc_STRVAR(index_doc, "Raise ValueError if the value is not present."); static PyMethodDef range_methods[] = { - {"__reversed__", (PyCFunction)range_reverse, METH_NOARGS, reverse_doc}, + {"__reversed__", range_reverse, METH_NOARGS, reverse_doc}, {"__reduce__", (PyCFunction)range_reduce, METH_VARARGS}, {"count", (PyCFunction)range_count, METH_O, count_doc}, {"index", (PyCFunction)range_index, METH_O, index_doc}, @@ -731,7 +731,7 @@ rangeiter_next(rangeiterobject *r) } static PyObject * -rangeiter_len(rangeiterobject *r) +rangeiter_len(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong(r->len - r->index); } @@ -740,7 +740,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -rangeiter_reduce(rangeiterobject *r) +rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) { PyObject *start=NULL, *stop=NULL, *step=NULL; PyObject *range; @@ -896,7 +896,7 @@ longrangeiter_len(longrangeiterobject *r, PyObject *no_args) } static PyObject * -longrangeiter_reduce(longrangeiterobject *r) +longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) { PyObject *product, *stop=NULL; PyObject *range; @@ -1081,7 +1081,7 @@ range_iter(PyObject *seq) } static PyObject * -range_reverse(PyObject *seq) +range_reverse(PyObject *seq, PyObject *Py_UNUSED(ignored)) { rangeobject *range = (rangeobject*) seq; longrangeiterobject *it; diff --git a/Objects/setobject.c b/Objects/setobject.c index 47db6b245ca63c..80101dda9beef8 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -703,7 +703,7 @@ set_merge(PySetObject *so, PyObject *otherset) } static PyObject * -set_pop(PySetObject *so) +set_pop(PySetObject *so, PyObject *Py_UNUSED(ignored)) { /* Make sure the search finger is in bounds */ Py_ssize_t i = so->finger & so->mask; @@ -833,7 +833,7 @@ setiter_traverse(setiterobject *si, visitproc visit, void *arg) } static PyObject * -setiter_len(setiterobject *si) +setiter_len(setiterobject *si, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (si->si_set != NULL && si->si_used == si->si_set->used) @@ -846,7 +846,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject *setiter_iternext(setiterobject *si); static PyObject * -setiter_reduce(setiterobject *si) +setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) { PyObject *list; setiterobject tmp; @@ -1175,25 +1175,25 @@ set_swap_bodies(PySetObject *a, PySetObject *b) } static PyObject * -set_copy(PySetObject *so) +set_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) { return make_new_set_basetype(Py_TYPE(so), (PyObject *)so); } static PyObject * -frozenset_copy(PySetObject *so) +frozenset_copy(PySetObject *so, PyObject *Py_UNUSED(ignored)) { if (PyFrozenSet_CheckExact(so)) { Py_INCREF(so); return (PyObject *)so; } - return set_copy(so); + return set_copy(so, NULL); } PyDoc_STRVAR(copy_doc, "Return a shallow copy of a set."); static PyObject * -set_clear(PySetObject *so) +set_clear(PySetObject *so, PyObject *Py_UNUSED(ignored)) { set_clear_internal(so); Py_RETURN_NONE; @@ -1208,7 +1208,7 @@ set_union(PySetObject *so, PyObject *args) PyObject *other; Py_ssize_t i; - result = (PySetObject *)set_copy(so); + result = (PySetObject *)set_copy(so, NULL); if (result == NULL) return NULL; @@ -1237,7 +1237,7 @@ set_or(PySetObject *so, PyObject *other) if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) Py_RETURN_NOTIMPLEMENTED; - result = (PySetObject *)set_copy(so); + result = (PySetObject *)set_copy(so, NULL); if (result == NULL) return NULL; if ((PyObject *)so == other) @@ -1270,7 +1270,7 @@ set_intersection(PySetObject *so, PyObject *other) int rv; if ((PyObject *)so == other) - return set_copy(so); + return set_copy(so, NULL); result = (PySetObject *)make_new_set_basetype(Py_TYPE(so), NULL); if (result == NULL) @@ -1343,7 +1343,7 @@ set_intersection_multi(PySetObject *so, PyObject *args) PyObject *result = (PyObject *)so; if (PyTuple_GET_SIZE(args) == 0) - return set_copy(so); + return set_copy(so, NULL); Py_INCREF(so); for (i=0 ; istart, self->stop, self->step); } diff --git a/Objects/stringlib/ctype.h b/Objects/stringlib/ctype.h index fd7b1bd49e54f7..843cfa22a84546 100644 --- a/Objects/stringlib/ctype.h +++ b/Objects/stringlib/ctype.h @@ -5,49 +5,49 @@ #include "bytes_methods.h" static PyObject* -stringlib_isspace(PyObject *self) +stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isalpha(PyObject *self) +stringlib_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isalnum(PyObject *self) +stringlib_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isascii(PyObject *self) +stringlib_isascii(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isdigit(PyObject *self) +stringlib_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_islower(PyObject *self) +stringlib_islower(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_isupper(PyObject *self) +stringlib_isupper(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } static PyObject* -stringlib_istitle(PyObject *self) +stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored)) { return _Py_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self)); } @@ -56,7 +56,7 @@ stringlib_istitle(PyObject *self) /* functions that return a new object partially translated by ctype funcs: */ static PyObject* -stringlib_lower(PyObject *self) +stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -68,7 +68,7 @@ stringlib_lower(PyObject *self) } static PyObject* -stringlib_upper(PyObject *self) +stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -80,7 +80,7 @@ stringlib_upper(PyObject *self) } static PyObject* -stringlib_title(PyObject *self) +stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -92,7 +92,7 @@ stringlib_title(PyObject *self) } static PyObject* -stringlib_capitalize(PyObject *self) +stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); @@ -104,7 +104,7 @@ stringlib_capitalize(PyObject *self) } static PyObject* -stringlib_swapcase(PyObject *self) +stringlib_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyObject* newobj; newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); diff --git a/Objects/structseq.c b/Objects/structseq.c index 1b71f724a66b09..1705837f71fa57 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -240,7 +240,7 @@ structseq_repr(PyStructSequence *obj) } static PyObject * -structseq_reduce(PyStructSequence* self) +structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) { PyObject* tup = NULL; PyObject* dict = NULL; diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 9bb91a5e65a0a0..e268f75be7172f 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -989,7 +989,7 @@ tupleiter_next(tupleiterobject *it) } static PyObject * -tupleiter_len(tupleiterobject *it) +tupleiter_len(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -1000,7 +1000,7 @@ tupleiter_len(tupleiterobject *it) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -tupleiter_reduce(tupleiterobject *it) +tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq) return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1ae2f5e018fe8e..ce56b04e6dec06 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13792,7 +13792,7 @@ unicode_sizeof_impl(PyObject *self) } static PyObject * -unicode_getnewargs(PyObject *v) +unicode_getnewargs(PyObject *v, PyObject *Py_UNUSED(ignored)) { PyObject *copy = _PyUnicode_Copy(v); if (!copy) @@ -13853,7 +13853,7 @@ static PyMethodDef unicode_methods[] = { {"_decimal2ascii", (PyCFunction) unicode__decimal2ascii, METH_NOARGS}, #endif - {"__getnewargs__", (PyCFunction)unicode_getnewargs, METH_NOARGS}, + {"__getnewargs__", unicode_getnewargs, METH_NOARGS}, {NULL, NULL} }; @@ -15334,7 +15334,7 @@ unicodeiter_next(unicodeiterobject *it) } static PyObject * -unicodeiter_len(unicodeiterobject *it) +unicodeiter_len(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { Py_ssize_t len = 0; if (it->it_seq) @@ -15345,7 +15345,7 @@ unicodeiter_len(unicodeiterobject *it) PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it))."); static PyObject * -unicodeiter_reduce(unicodeiterobject *it) +unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"), diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index f600179d0e9bac..9f492e4b25e49f 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -452,7 +452,7 @@ proxy_checkref(PyWeakReference *proxy) #define WRAP_METHOD(method, special) \ static PyObject * \ - method(PyObject *proxy) { \ + method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ _Py_IDENTIFIER(special); \ UNWRAP(proxy); \ return _PyObject_CallMethodId(proxy, &PyId_##special, NULL); \ @@ -602,7 +602,7 @@ WRAP_METHOD(proxy_bytes, __bytes__) static PyMethodDef proxy_methods[] = { - {"__bytes__", (PyCFunction)proxy_bytes, METH_NOARGS}, + {"__bytes__", proxy_bytes, METH_NOARGS}, {NULL, NULL} }; diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c index 04323ebd170681..6d01ad5c2d50e7 100644 --- a/PC/bdist_wininst/install.c +++ b/PC/bdist_wininst/install.c @@ -631,19 +631,18 @@ static PyObject *PyMessageBox(PyObject *self, PyObject *args) return g_Py_BuildValue("i", rc); } -static PyObject *GetRootHKey(PyObject *self) +static PyObject *GetRootHKey(PyObject *self, PyObject *Py_UNUSED(ignored)) { return g_PyLong_FromVoidPtr(hkey_root); } #define METH_VARARGS 0x0001 #define METH_NOARGS 0x0004 -typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); PyMethodDef meth[] = { {"create_shortcut", CreateShortcut, METH_VARARGS, NULL}, {"get_special_folder_path", GetSpecialFolderPath, METH_VARARGS, NULL}, - {"get_root_hkey", (PyCFunction)GetRootHKey, METH_NOARGS, NULL}, + {"get_root_hkey", GetRootHKey, METH_NOARGS, NULL}, {"file_created", FileCreated, METH_VARARGS, NULL}, {"directory_created", DirectoryCreated, METH_VARARGS, NULL}, {"message_box", PyMessageBox, METH_VARARGS, NULL}, diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 94f290853ccf9f..839258b87495cc 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -619,7 +619,7 @@ filter_next(filterobject *lz) } static PyObject * -filter_reduce(filterobject *lz) +filter_reduce(filterobject *lz, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it); } @@ -1331,7 +1331,7 @@ map_next(mapobject *lz) } static PyObject * -map_reduce(mapobject *lz) +map_reduce(mapobject *lz, PyObject *Py_UNUSED(ignored)) { Py_ssize_t numargs = PyTuple_GET_SIZE(lz->iters); PyObject *args = PyTuple_New(numargs+1); @@ -2656,7 +2656,7 @@ zip_next(zipobject *lz) } static PyObject * -zip_reduce(zipobject *lz) +zip_reduce(zipobject *lz, PyObject *Py_UNUSED(ignored)) { /* Just recreate the zip with the internal iterator tuple */ return Py_BuildValue("OO", Py_TYPE(lz), lz->ittuple); diff --git a/Python/compile.c b/Python/compile.c index 62fe971739d457..7960f09319e777 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -171,7 +171,6 @@ static void compiler_free(struct compiler *); static basicblock *compiler_new_block(struct compiler *); static int compiler_next_instr(struct compiler *, basicblock *); static int compiler_addop(struct compiler *, int); -static int compiler_addop_o(struct compiler *, int, PyObject *, PyObject *); static int compiler_addop_i(struct compiler *, int, Py_ssize_t); static int compiler_addop_j(struct compiler *, int, basicblock *, int); static int compiler_error(struct compiler *, const char *); @@ -407,14 +406,11 @@ list2dict(PyObject *list) return NULL; } k = PyList_GET_ITEM(list, i); - k = _PyCode_ConstantKey(k); - if (k == NULL || PyDict_SetItem(dict, k, v) < 0) { - Py_XDECREF(k); + if (PyDict_SetItem(dict, k, v) < 0) { Py_DECREF(v); Py_DECREF(dict); return NULL; } - Py_DECREF(k); Py_DECREF(v); } return dict; @@ -463,23 +459,20 @@ dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset) scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK; if (scope == scope_type || vi & flag) { - PyObject *tuple, *item = PyLong_FromSsize_t(i); + PyObject *item = PyLong_FromSsize_t(i); if (item == NULL) { Py_DECREF(sorted_keys); Py_DECREF(dest); return NULL; } i++; - tuple = _PyCode_ConstantKey(k); - if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) { + if (PyDict_SetItem(dest, k, item) < 0) { Py_DECREF(sorted_keys); Py_DECREF(item); Py_DECREF(dest); - Py_XDECREF(tuple); return NULL; } Py_DECREF(item); - Py_DECREF(tuple); } } Py_DECREF(sorted_keys); @@ -565,7 +558,7 @@ compiler_enter_scope(struct compiler *c, identifier name, if (u->u_ste->ste_needs_class_closure) { /* Cook up an implicit __class__ cell. */ _Py_IDENTIFIER(__class__); - PyObject *tuple, *name; + PyObject *name; int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(PyDict_GET_SIZE(u->u_cellvars) == 0); @@ -574,13 +567,7 @@ compiler_enter_scope(struct compiler *c, identifier name, compiler_unit_free(u); return 0; } - tuple = _PyCode_ConstantKey(name); - if (!tuple) { - compiler_unit_free(u); - return 0; - } - res = PyDict_SetItem(u->u_cellvars, tuple, _PyLong_Zero); - Py_DECREF(tuple); + res = PyDict_SetItem(u->u_cellvars, name, _PyLong_Zero); if (res < 0) { compiler_unit_free(u); return 0; @@ -872,6 +859,10 @@ static int stack_effect(int opcode, int oparg, int jump) { switch (opcode) { + case NOP: + case EXTENDED_ARG: + return 0; + /* Stack manipulation */ case POP_TOP: return -1; @@ -1158,27 +1149,20 @@ compiler_addop(struct compiler *c, int opcode) static Py_ssize_t compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o) { - PyObject *t, *v; + PyObject *v; Py_ssize_t arg; - t = _PyCode_ConstantKey(o); - if (t == NULL) - return -1; - - v = PyDict_GetItem(dict, t); + v = PyDict_GetItemWithError(dict, o); if (!v) { if (PyErr_Occurred()) { - Py_DECREF(t); return -1; } arg = PyDict_GET_SIZE(dict); v = PyLong_FromSsize_t(arg); if (!v) { - Py_DECREF(t); return -1; } - if (PyDict_SetItem(dict, t, v) < 0) { - Py_DECREF(t); + if (PyDict_SetItem(dict, o, v) < 0) { Py_DECREF(v); return -1; } @@ -1186,10 +1170,33 @@ compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o) } else arg = PyLong_AsLong(v); + return arg; +} + +static Py_ssize_t +compiler_add_const(struct compiler *c, PyObject *o) +{ + PyObject *t; + Py_ssize_t arg; + + t = _PyCode_ConstantKey(o); + if (t == NULL) + return -1; + + arg = compiler_add_o(c, c->u->u_consts, t); Py_DECREF(t); return arg; } +static int +compiler_addop_load_const(struct compiler *c, PyObject *o) +{ + Py_ssize_t arg = compiler_add_const(c, o); + if (arg < 0) + return 0; + return compiler_addop_i(c, LOAD_CONST, arg); +} + static int compiler_addop_o(struct compiler *c, int opcode, PyObject *dict, PyObject *o) @@ -1290,6 +1297,24 @@ compiler_addop_j(struct compiler *c, int opcode, basicblock *b, int absolute) } \ } +#define ADDOP_LOAD_CONST(C, O) { \ + if (!compiler_addop_load_const((C), (O))) \ + return 0; \ +} + +/* Same as ADDOP_LOAD_CONST, but steals a reference. */ +#define ADDOP_LOAD_CONST_NEW(C, O) { \ + PyObject *__new_const = (O); \ + if (__new_const == NULL) { \ + return 0; \ + } \ + if (!compiler_addop_load_const((C), __new_const)) { \ + Py_DECREF(__new_const); \ + return 0; \ + } \ + Py_DECREF(__new_const); \ +} + #define ADDOP_O(C, OP, O, TYPE) { \ if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) \ return 0; \ @@ -1534,7 +1559,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info, ADDOP(c, WITH_CLEANUP_START); if (info->fb_type == ASYNC_WITH) { ADDOP(c, GET_AWAITABLE); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); } ADDOP(c, WITH_CLEANUP_FINISH); @@ -1579,7 +1604,7 @@ compiler_body(struct compiler *c, asdl_seq *stmts, string docstring) } /* if not -OO mode, set docstring */ if (c->c_optimize < 2 && docstring) { - ADDOP_O(c, LOAD_CONST, docstring, consts); + ADDOP_LOAD_CONST(c, docstring); ADDOP_NAME(c, STORE_NAME, __doc__, names); } VISIT_SEQ(c, stmt, stmts); @@ -1668,12 +1693,8 @@ get_ref_type(struct compiler *c, PyObject *name) static int compiler_lookup_arg(PyObject *dict, PyObject *name) { - PyObject *k, *v; - k = _PyCode_ConstantKey(name); - if (k == NULL) - return -1; - v = PyDict_GetItem(dict, k); - Py_DECREF(k); + PyObject *v; + v = PyDict_GetItem(dict, name); if (v == NULL) return -1; return PyLong_AS_LONG(v); @@ -1721,8 +1742,8 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t flags, Py flags |= 0x08; ADDOP_I(c, BUILD_TUPLE, free); } - ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); - ADDOP_O(c, LOAD_CONST, qualname, consts); + ADDOP_LOAD_CONST(c, (PyObject*)co); + ADDOP_LOAD_CONST(c, qualname); ADDOP_I(c, MAKE_FUNCTION, flags); return 1; } @@ -1784,10 +1805,7 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs, Py_ssize_t default_count = PyList_GET_SIZE(keys); PyObject *keys_tuple = PyList_AsTuple(keys); Py_DECREF(keys); - if (keys_tuple == NULL) { - return 0; - } - ADDOP_N(c, LOAD_CONST, keys_tuple, consts); + ADDOP_LOAD_CONST_NEW(c, keys_tuple); ADDOP_I(c, BUILD_CONST_KEY_MAP, default_count); assert(default_count > 0); return 1; @@ -1804,12 +1822,7 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs, static int compiler_visit_annexpr(struct compiler *c, expr_ty annotation) { - PyObject *ann_as_str; - ann_as_str = _PyAST_ExprAsUnicode(annotation, 1); - if (!ann_as_str) { - return 0; - } - ADDOP_N(c, LOAD_CONST, ann_as_str, consts); + ADDOP_LOAD_CONST_NEW(c, _PyAST_ExprAsUnicode(annotation, 1)); return 1; } @@ -1896,10 +1909,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, if (len) { PyObject *keytuple = PyList_AsTuple(names); Py_DECREF(names); - if (keytuple == NULL) { - return 0; - } - ADDOP_N(c, LOAD_CONST, keytuple, consts); + ADDOP_LOAD_CONST_NEW(c, keytuple); ADDOP_I(c, BUILD_CONST_KEY_MAP, len); return 1; } @@ -2002,7 +2012,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async) /* if not -OO mode, add docstring */ if (c->c_optimize < 2 && s->v.FunctionDef.docstring) docstring = s->v.FunctionDef.docstring; - if (compiler_add_o(c, c->u->u_consts, docstring) < 0) { + if (compiler_add_const(c, docstring) < 0) { compiler_exit_scope(c); return 0; } @@ -2082,7 +2092,7 @@ compiler_class(struct compiler *c, stmt_ty s) } Py_DECREF(str); assert(c->u->u_qualname); - ADDOP_O(c, LOAD_CONST, c->u->u_qualname, consts); + ADDOP_LOAD_CONST(c, c->u->u_qualname); str = PyUnicode_InternFromString("__qualname__"); if (!str || !compiler_nameop(c, str, Store)) { Py_XDECREF(str); @@ -2124,7 +2134,7 @@ compiler_class(struct compiler *c, stmt_ty s) else { /* No methods referenced __class__, so just return None */ assert(PyDict_GET_SIZE(c->u->u_cellvars) == 0); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); } ADDOP_IN_SCOPE(c, RETURN_VALUE); /* create the code object */ @@ -2143,7 +2153,7 @@ compiler_class(struct compiler *c, stmt_ty s) Py_DECREF(co); /* 4. load class name */ - ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts); + ADDOP_LOAD_CONST(c, s->v.ClassDef.name); /* 5. generate the rest of the code for the call */ if (!compiler_call_helper(c, 2, @@ -2336,7 +2346,7 @@ compiler_lambda(struct compiler *c, expr_ty e) /* Make None the first constant, so the lambda can't have a docstring. */ - if (compiler_add_o(c, c->u->u_consts, Py_None) < 0) + if (compiler_add_const(c, Py_None) < 0) return 0; c->u->u_argcount = asdl_seq_LEN(args->args); @@ -2437,6 +2447,10 @@ static int compiler_async_for(struct compiler *c, stmt_ty s) { basicblock *start, *except, *end; + if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) { + return compiler_error(c, "'async for' outside async function"); + } + start = compiler_new_block(c); except = compiler_new_block(c); end = compiler_new_block(c); @@ -2454,7 +2468,7 @@ compiler_async_for(struct compiler *c, stmt_ty s) /* SETUP_FINALLY to guard the __anext__ call */ ADDOP_JREL(c, SETUP_FINALLY, except); ADDOP(c, GET_ANEXT); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); ADDOP(c, POP_BLOCK); /* for SETUP_FINALLY */ @@ -2553,7 +2567,7 @@ compiler_return(struct compiler *c, stmt_ty s) return 0; } if (s->v.Return.value == NULL) { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); } else if (!preserve_tos) { VISIT(c, expr, s->v.Return.value); @@ -2776,7 +2790,7 @@ compiler_try_except(struct compiler *c, stmt_ty s) return 0; /* name = None; del name */ - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); compiler_nameop(c, handler->v.ExceptHandler.name, Store); compiler_nameop(c, handler->v.ExceptHandler.name, Del); @@ -2875,8 +2889,8 @@ compiler_import(struct compiler *c, stmt_ty s) alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i); int r; - ADDOP_O(c, LOAD_CONST, _PyLong_Zero, consts); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, _PyLong_Zero); + ADDOP_LOAD_CONST(c, Py_None); ADDOP_NAME(c, IMPORT_NAME, alias->name, names); if (alias->asname) { @@ -2908,7 +2922,7 @@ static int compiler_from_import(struct compiler *c, stmt_ty s) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names); - PyObject *level, *names; + PyObject *names; static PyObject *empty_string; if (!empty_string) { @@ -2917,11 +2931,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) return 0; } - level = PyLong_FromLong(s->v.ImportFrom.level); - if (!level) { - return 0; - } - ADDOP_N(c, LOAD_CONST, level, consts); + ADDOP_LOAD_CONST_NEW(c, PyLong_FromLong(s->v.ImportFrom.level)); names = PyTuple_New(n); if (!names) @@ -2940,7 +2950,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) return compiler_error(c, "from __future__ imports must occur " "at the beginning of the file"); } - ADDOP_N(c, LOAD_CONST, names, consts); + ADDOP_LOAD_CONST_NEW(c, names); if (s->v.ImportFrom.module) { ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); @@ -3496,7 +3506,7 @@ compiler_subdict(struct compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end Py_INCREF(key); PyTuple_SET_ITEM(keys, i - begin, key); } - ADDOP_N(c, LOAD_CONST, keys, consts); + ADDOP_LOAD_CONST_NEW(c, keys); ADDOP_I(c, BUILD_CONST_KEY_MAP, n); } else { @@ -3706,14 +3716,14 @@ compiler_subkwargs(struct compiler *c, asdl_seq *keywords, Py_ssize_t begin, Py_ Py_INCREF(key); PyTuple_SET_ITEM(keys, i - begin, key); } - ADDOP_N(c, LOAD_CONST, keys, consts); + ADDOP_LOAD_CONST_NEW(c, keys); ADDOP_I(c, BUILD_CONST_KEY_MAP, n); } else { /* a for loop only executes once */ for (i = begin; i < end; i++) { kw = asdl_seq_GET(keywords, i); - ADDOP_O(c, LOAD_CONST, kw->arg, consts); + ADDOP_LOAD_CONST(c, kw->arg); VISIT(c, expr, kw->value); } ADDOP_I(c, BUILD_MAP, n); @@ -3823,7 +3833,7 @@ compiler_call_helper(struct compiler *c, Py_INCREF(kw->arg); PyTuple_SET_ITEM(names, i, kw->arg); } - ADDOP_N(c, LOAD_CONST, names, consts); + ADDOP_LOAD_CONST_NEW(c, names); ADDOP_I(c, CALL_FUNCTION_KW, n + nelts + nkwelts); return 1; } @@ -3987,7 +3997,7 @@ compiler_async_comprehension_generator(struct compiler *c, ADDOP_JREL(c, SETUP_FINALLY, except); ADDOP(c, GET_ANEXT); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); ADDOP(c, POP_BLOCK); VISIT(c, expr, gen->target); @@ -4127,7 +4137,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, if (is_async_generator && type != COMP_GENEXP) { ADDOP(c, GET_AWAITABLE); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); } @@ -4256,6 +4266,9 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos) withitem_ty item = asdl_seq_GET(s->v.AsyncWith.items, pos); assert(s->kind == AsyncWith_kind); + if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION) { + return compiler_error(c, "'async with' outside async function"); + } block = compiler_new_block(c); finally = compiler_new_block(c); @@ -4267,7 +4280,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos) ADDOP(c, BEFORE_ASYNC_WITH); ADDOP(c, GET_AWAITABLE); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); ADDOP_JREL(c, SETUP_ASYNC_WITH, finally); @@ -4308,7 +4321,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos) ADDOP(c, WITH_CLEANUP_START); ADDOP(c, GET_AWAITABLE); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); ADDOP(c, WITH_CLEANUP_FINISH); @@ -4449,7 +4462,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e) VISIT(c, expr, e->v.Yield.value); } else { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); } ADDOP(c, YIELD_VALUE); break; @@ -4462,7 +4475,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e) VISIT(c, expr, e->v.YieldFrom.value); ADDOP(c, GET_YIELD_FROM_ITER); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); break; case Await_kind: @@ -4475,7 +4488,7 @@ compiler_visit_expr(struct compiler *c, expr_ty e) VISIT(c, expr, e->v.Await.value); ADDOP(c, GET_AWAITABLE); - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, YIELD_FROM); break; case Compare_kind: @@ -4483,26 +4496,26 @@ compiler_visit_expr(struct compiler *c, expr_ty e) case Call_kind: return compiler_call(c, e); case Constant_kind: - ADDOP_O(c, LOAD_CONST, e->v.Constant.value, consts); + ADDOP_LOAD_CONST(c, e->v.Constant.value); break; case Num_kind: - ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts); + ADDOP_LOAD_CONST(c, e->v.Num.n); break; case Str_kind: - ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); + ADDOP_LOAD_CONST(c, e->v.Str.s); break; case JoinedStr_kind: return compiler_joined_str(c, e); case FormattedValue_kind: return compiler_formatted_value(c, e); case Bytes_kind: - ADDOP_O(c, LOAD_CONST, e->v.Bytes.s, consts); + ADDOP_LOAD_CONST(c, e->v.Bytes.s); break; case Ellipsis_kind: - ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); + ADDOP_LOAD_CONST(c, Py_Ellipsis); break; case NameConstant_kind: - ADDOP_O(c, LOAD_CONST, e->v.NameConstant.value, consts); + ADDOP_LOAD_CONST(c, e->v.NameConstant.value); break; /* The following exprs can be assignment targets. */ case Attribute_kind: @@ -4739,10 +4752,7 @@ compiler_annassign(struct compiler *c, stmt_ty s) } ADDOP_NAME(c, LOAD_NAME, __annotations__, names); mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id); - if (!mangled) { - return 0; - } - ADDOP_N(c, LOAD_CONST, mangled, consts); + ADDOP_LOAD_CONST_NEW(c, mangled); ADDOP(c, STORE_SUBSCR); } break; @@ -4842,14 +4852,14 @@ compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) VISIT(c, expr, s->v.Slice.lower); } else { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); } if (s->v.Slice.upper) { VISIT(c, expr, s->v.Slice.upper); } else { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); } if (s->v.Slice.step) { @@ -5299,10 +5309,6 @@ dict_keys_inorder(PyObject *dict, Py_ssize_t offset) return NULL; while (PyDict_Next(dict, &pos, &k, &v)) { i = PyLong_AS_LONG(v); - /* The keys of the dictionary are tuples. (see compiler_add_o - * and _PyCode_ConstantKey). The object we want is always second, - * though. */ - k = PyTuple_GET_ITEM(k, 1); Py_INCREF(k); assert((i - offset) < size); assert((i - offset) >= 0); @@ -5311,6 +5317,31 @@ dict_keys_inorder(PyObject *dict, Py_ssize_t offset) return tuple; } +static PyObject * +consts_dict_keys_inorder(PyObject *dict) +{ + PyObject *consts, *k, *v; + Py_ssize_t i, pos = 0, size = PyDict_GET_SIZE(dict); + + consts = PyList_New(size); /* PyCode_Optimize() requires a list */ + if (consts == NULL) + return NULL; + while (PyDict_Next(dict, &pos, &k, &v)) { + i = PyLong_AS_LONG(v); + /* The keys of the dictionary can be tuples wrapping a contant. + * (see compiler_add_o and _PyCode_ConstantKey). In that case + * the object we want is always second. */ + if (PyTuple_CheckExact(k)) { + k = PyTuple_GET_ITEM(k, 1); + } + Py_INCREF(k); + assert(i < size); + assert(i >= 0); + PyList_SET_ITEM(consts, i, k); + } + return consts; +} + static int compute_code_flags(struct compiler *c) { @@ -5355,12 +5386,7 @@ makecode(struct compiler *c, struct assembler *a) int flags; int argcount, kwonlyargcount, maxdepth; - tmp = dict_keys_inorder(c->u->u_consts, 0); - if (!tmp) - goto error; - consts = PySequence_List(tmp); /* optimize_code requires a list */ - Py_DECREF(tmp); - + consts = consts_dict_keys_inorder(c->u->u_consts); names = dict_keys_inorder(c->u->u_names, 0); varnames = dict_keys_inorder(c->u->u_varnames, 0); if (!consts || !names || !varnames) @@ -5369,7 +5395,7 @@ makecode(struct compiler *c, struct assembler *a) cellvars = dict_keys_inorder(c->u->u_cellvars, 0); if (!cellvars) goto error; - freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars)); + freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_GET_SIZE(cellvars)); if (!freevars) goto error; @@ -5465,7 +5491,7 @@ assemble(struct compiler *c, int addNone) if (!c->u->u_curblock->b_return) { NEXT_BLOCK(c); if (addNone) - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_LOAD_CONST(c, Py_None); ADDOP(c, RETURN_VALUE); } diff --git a/Python/fileutils.c b/Python/fileutils.c index 32aeea4f10374b..35869c81ac9f74 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -431,7 +431,7 @@ decode_current_locale(const char* arg, wchar_t **wstr, size_t *wlen, can be decoded as a surrogate character, escape the bytes using the surrogateescape error handler instead of decoding them. - On sucess, return 0 and write the newly allocated wide character string into + On success, return 0 and write the newly allocated wide character string into *wstr (use PyMem_RawFree() to free the memory). If wlen is not NULL, write the number of wide characters excluding the null character into *wlen. diff --git a/Python/hamt.c b/Python/hamt.c index 53a85723745ecb..52171222b005ee 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -39,7 +39,7 @@ Now let's partition this bit representation of the hash into blocks of 0b00_00000_10010_11101_00101_01011_10000 = 19830128 (6) (5) (4) (3) (2) (1) -Each block of 5 bits represents a number betwen 0 and 31. So if we have +Each block of 5 bits represents a number between 0 and 31. So if we have a tree that consists of nodes, each of which is an array of 32 pointers, those 5-bit blocks will encode a position on a single tree level. @@ -832,7 +832,7 @@ hamt_node_bitmap_assoc(PyHamtNode_Bitmap *self, pairs. Small hamt objects (<30 keys) usually don't have any - Array nodes at all. Betwen ~30 and ~400 keys hamt + Array nodes at all. Between ~30 and ~400 keys hamt objects usually have one Array node, and usually it's a root node. */ diff --git a/Python/import.c b/Python/import.c index 9f46da336234f1..bb1d69e1689572 100644 --- a/Python/import.c +++ b/Python/import.c @@ -364,7 +364,7 @@ PyImport_GetModule(PyObject *name) } else { m = PyObject_GetItem(modules, name); - if (PyErr_ExceptionMatches(PyExc_KeyError)) { + if (m == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_Clear(); } } @@ -416,12 +416,16 @@ PyImport_Cleanup(void) if (Py_VerboseFlag) PySys_WriteStderr("# clear builtins._\n"); - PyDict_SetItemString(interp->builtins, "_", Py_None); + if (PyDict_SetItemString(interp->builtins, "_", Py_None) < 0) { + PyErr_WriteUnraisable(NULL); + } for (p = sys_deletes; *p != NULL; p++) { if (Py_VerboseFlag) PySys_WriteStderr("# clear sys.%s\n", *p); - PyDict_SetItemString(interp->sysdict, *p, Py_None); + if (PyDict_SetItemString(interp->sysdict, *p, Py_None) < 0) { + PyErr_WriteUnraisable(NULL); + } } for (p = sys_files; *p != NULL; p+=2) { if (Py_VerboseFlag) @@ -429,7 +433,9 @@ PyImport_Cleanup(void) value = PyDict_GetItemString(interp->sysdict, *(p+1)); if (value == NULL) value = Py_None; - PyDict_SetItemString(interp->sysdict, *p, value); + if (PyDict_SetItemString(interp->sysdict, *p, value) < 0) { + PyErr_WriteUnraisable(NULL); + } } /* We prepare a list which will receive (name, weakref) tuples of @@ -437,27 +443,33 @@ PyImport_Cleanup(void) for diagnosis messages (in verbose mode), while the weakref helps detect those modules which have been held alive. */ weaklist = PyList_New(0); - if (weaklist == NULL) - PyErr_Clear(); + if (weaklist == NULL) { + PyErr_WriteUnraisable(NULL); + } #define STORE_MODULE_WEAKREF(name, mod) \ if (weaklist != NULL) { \ PyObject *wr = PyWeakref_NewRef(mod, NULL); \ - if (name && wr) { \ + if (wr) { \ PyObject *tup = PyTuple_Pack(2, name, wr); \ - PyList_Append(weaklist, tup); \ + if (!tup || PyList_Append(weaklist, tup) < 0) { \ + PyErr_WriteUnraisable(NULL); \ + } \ Py_XDECREF(tup); \ + Py_DECREF(wr); \ + } \ + else { \ + PyErr_WriteUnraisable(NULL); \ } \ - Py_XDECREF(wr); \ - if (PyErr_Occurred()) \ - PyErr_Clear(); \ } #define CLEAR_MODULE(name, mod) \ if (PyModule_Check(mod)) { \ if (Py_VerboseFlag && PyUnicode_Check(name)) \ PySys_FormatStderr("# cleanup[2] removing %U\n", name); \ STORE_MODULE_WEAKREF(name, mod); \ - PyObject_SetItem(modules, name, Py_None); \ + if (PyObject_SetItem(modules, name, Py_None) < 0) { \ + PyErr_WriteUnraisable(NULL); \ + } \ } /* Remove all modules from sys.modules, hoping that garbage collection @@ -471,19 +483,22 @@ PyImport_Cleanup(void) else { PyObject *iterator = PyObject_GetIter(modules); if (iterator == NULL) { - PyErr_Clear(); + PyErr_WriteUnraisable(NULL); } else { while ((key = PyIter_Next(iterator))) { value = PyObject_GetItem(modules, key); if (value == NULL) { - PyErr_Clear(); + PyErr_WriteUnraisable(NULL); continue; } CLEAR_MODULE(key, value); Py_DECREF(value); Py_DECREF(key); } + if (PyErr_Occurred()) { + PyErr_WriteUnraisable(NULL); + } Py_DECREF(iterator); } } @@ -494,17 +509,20 @@ PyImport_Cleanup(void) } else { _Py_IDENTIFIER(clear); - if (_PyObject_CallMethodId(modules, &PyId_clear, "") == NULL) - PyErr_Clear(); + if (_PyObject_CallMethodId(modules, &PyId_clear, "") == NULL) { + PyErr_WriteUnraisable(NULL); + } } /* Restore the original builtins dict, to ensure that any user data gets cleared. */ dict = PyDict_Copy(interp->builtins); - if (dict == NULL) - PyErr_Clear(); + if (dict == NULL) { + PyErr_WriteUnraisable(NULL); + } PyDict_Clear(interp->builtins); - if (PyDict_Update(interp->builtins, interp->builtins_copy)) + if (PyDict_Update(interp->builtins, interp->builtins_copy)) { PyErr_Clear(); + } Py_XDECREF(dict); /* Clear module dict copies stored in the interpreter state */ _PyState_ClearModules(); @@ -564,6 +582,7 @@ PyImport_Cleanup(void) /* Once more */ _PyGC_CollectNoFail(); +#undef CLEAR_MODULE #undef STORE_MODULE_WEAKREF } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index a9b9470c726521..958219b744580d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -325,11 +325,6 @@ initimport(PyInterpreterState *interp, PyObject *sysmod) /* Install importlib as the implementation of import */ value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod); - if (value != NULL) { - Py_DECREF(value); - value = PyObject_CallMethod(importlib, - "_install_external_importers", ""); - } if (value == NULL) { PyErr_Print(); return _Py_INIT_ERR("importlib install failed"); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 7cecff67486a2a..3fab81aa50536f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -357,7 +357,7 @@ exit status will be one (i.e., failure)." static PyObject * -sys_getdefaultencoding(PyObject *self) +sys_getdefaultencoding(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyUnicode_FromString(PyUnicode_GetDefaultEncoding()); } @@ -370,7 +370,7 @@ implementation." ); static PyObject * -sys_getfilesystemencoding(PyObject *self) +sys_getfilesystemencoding(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (Py_FileSystemDefaultEncoding) return PyUnicode_FromString(Py_FileSystemDefaultEncoding); @@ -387,7 +387,7 @@ operating system filenames." ); static PyObject * -sys_getfilesystemencodeerrors(PyObject *self) +sys_getfilesystemencodeerrors(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (Py_FileSystemDefaultEncodeErrors) return PyUnicode_FromString(Py_FileSystemDefaultEncodeErrors); @@ -988,7 +988,7 @@ dependent." ); static PyObject * -sys_getrecursionlimit(PyObject *self) +sys_getrecursionlimit(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromLong(Py_GetRecursionLimit()); } @@ -1274,7 +1274,7 @@ sys_getrefcount(PyObject *self, PyObject *arg) #ifdef Py_REF_DEBUG static PyObject * -sys_gettotalrefcount(PyObject *self) +sys_gettotalrefcount(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(_Py_GetRefTotal()); } @@ -1289,7 +1289,7 @@ reference as an argument to getrefcount()." ); static PyObject * -sys_getallocatedblocks(PyObject *self) +sys_getallocatedblocks(PyObject *self, PyObject *Py_UNUSED(ignored)) { return PyLong_FromSsize_t(_Py_GetAllocatedBlocks()); } @@ -1401,7 +1401,7 @@ a 11-tuple where the entries in the tuple are counts of:\n\ ); static PyObject * -sys_callstats(PyObject *self) +sys_callstats(PyObject *self, PyObject *Py_UNUSED(ignored)) { if (PyErr_WarnEx(PyExc_DeprecationWarning, "sys.callstats() has been deprecated in Python 3.7 " @@ -1493,7 +1493,7 @@ static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ {"breakpointhook", (PyCFunction)sys_breakpointhook, METH_FASTCALL | METH_KEYWORDS, breakpointhook_doc}, - {"callstats", (PyCFunction)sys_callstats, METH_NOARGS, + {"callstats", sys_callstats, METH_NOARGS, callstats_doc}, {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS, sys_clear_type_cache__doc__}, @@ -1503,13 +1503,13 @@ static PyMethodDef sys_methods[] = { {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, {"exit", sys_exit, METH_VARARGS, exit_doc}, - {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, + {"getdefaultencoding", sys_getdefaultencoding, METH_NOARGS, getdefaultencoding_doc}, #ifdef HAVE_DLOPEN {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, getdlopenflags_doc}, #endif - {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, + {"getallocatedblocks", sys_getallocatedblocks, METH_NOARGS, getallocatedblocks_doc}, #ifdef COUNT_ALLOCS {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, @@ -1517,18 +1517,18 @@ static PyMethodDef sys_methods[] = { #ifdef DYNAMIC_EXECUTION_PROFILE {"getdxp", _Py_GetDXProfile, METH_VARARGS}, #endif - {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, + {"getfilesystemencoding", sys_getfilesystemencoding, METH_NOARGS, getfilesystemencoding_doc}, - { "getfilesystemencodeerrors", (PyCFunction)sys_getfilesystemencodeerrors, + { "getfilesystemencodeerrors", sys_getfilesystemencodeerrors, METH_NOARGS, getfilesystemencodeerrors_doc }, #ifdef Py_TRACE_REFS {"getobjects", _Py_GetObjects, METH_VARARGS}, #endif #ifdef Py_REF_DEBUG - {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS}, + {"gettotalrefcount", sys_gettotalrefcount, METH_NOARGS}, #endif {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc}, - {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, + {"getrecursionlimit", sys_getrecursionlimit, METH_NOARGS, getrecursionlimit_doc}, {"getsizeof", (PyCFunction)sys_getsizeof, METH_VARARGS | METH_KEYWORDS, getsizeof_doc}, diff --git a/Python/traceback.c b/Python/traceback.c index b00864b06e43cd..21fb034160022b 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -87,7 +87,7 @@ tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame, } static PyObject * -tb_dir(PyTracebackObject *self) +tb_dir(PyTracebackObject *self, PyObject *Py_UNUSED(ignored)) { return Py_BuildValue("[ssss]", "tb_frame", "tb_next", "tb_lasti", "tb_lineno"); diff --git a/README.rst b/README.rst index 05daca298ae74a..5420558f0dcaad 100644 --- a/README.rst +++ b/README.rst @@ -92,15 +92,16 @@ below. Profile Guided Optimization ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -PGO takes advantage of recent versions of the GCC or Clang compilers. If ran, -``make profile-opt`` will do several steps. +PGO takes advantage of recent versions of the GCC or Clang compilers. If used, +either via ``configure --enable-optimizations`` above or by manually running +``make profile-opt`` regardless of configure flags it will do several steps. First, the entire Python directory is cleaned of temporary files that may have resulted in a previous compilation. Then, an instrumented version of the interpreter is built, using suitable -compiler flags for each flavour. Note that this is just an intermediary step -and the binary resulted after this step is not good for real life workloads, as +compiler flags for each flavour. Note that this is just an intermediary step. +The binary resulting from this step is not good for real life workloads as it has profiling instructions embedded inside. After this instrumented version of the interpreter is built, the Makefile will diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 839ce799797e72..7df7c9bd541672 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -730,7 +730,7 @@ def _get_entries(self, keys): else: offset = 8 * dk_size - ent_addr = keys['dk_indices']['as_1'].address + ent_addr = keys['dk_indices'].address ent_addr = ent_addr.cast(_type_unsigned_char_ptr()) + offset ent_ptr_t = gdb.lookup_type('PyDictKeyEntry').pointer() ent_addr = ent_addr.cast(ent_ptr_t) diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 13d7a649aec42e..b46dd339736f44 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -232,6 +232,10 @@ def escape_nonascii(s, encoding): return ''.join(escapes[b] for b in s.encode(encoding)) +def is_literal_string(s): + return s[0] in '\'"' or (s[0] in 'rRuU' and s[1] in '\'"') + + def safe_eval(s): # unwrap quotes, safely return eval(s, {'__builtins__':{}}, {}) @@ -317,8 +321,8 @@ def __init__(self, options): def __call__(self, ttype, tstring, stup, etup, line): # dispatch ## import token -## print >> sys.stderr, 'ttype:', token.tok_name[ttype], \ -## 'tstring:', tstring +## print('ttype:', token.tok_name[ttype], 'tstring:', tstring, +## file=sys.stderr) self.__state(ttype, tstring, stup[0]) def __waiting(self, ttype, tstring, lineno): @@ -327,7 +331,7 @@ def __waiting(self, ttype, tstring, lineno): if opts.docstrings and not opts.nodocstrings.get(self.__curfile): # module docstring? if self.__freshmodule: - if ttype == tokenize.STRING: + if ttype == tokenize.STRING and is_literal_string(tstring): self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__freshmodule = 0 elif ttype not in (tokenize.COMMENT, tokenize.NL): @@ -353,7 +357,7 @@ def __suiteseen(self, ttype, tstring, lineno): def __suitedocstring(self, ttype, tstring, lineno): # ignore any intervening noise - if ttype == tokenize.STRING: + if ttype == tokenize.STRING and is_literal_string(tstring): self.__addentry(safe_eval(tstring), lineno, isdocstring=1) self.__state = self.__waiting elif ttype not in (tokenize.NEWLINE, tokenize.INDENT, @@ -378,7 +382,7 @@ def __openseen(self, ttype, tstring, lineno): if self.__data: self.__addentry(EMPTYSTRING.join(self.__data)) self.__state = self.__waiting - elif ttype == tokenize.STRING: + elif ttype == tokenize.STRING and is_literal_string(tstring): self.__data.append(safe_eval(tstring)) elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL]: diff --git a/Tools/msi/tools/tools_files.wxs b/Tools/msi/tools/tools_files.wxs index 9c76b1b44460ab..3de6c9291cf676 100644 --- a/Tools/msi/tools/tools_files.wxs +++ b/Tools/msi/tools/tools_files.wxs @@ -8,9 +8,6 @@ - - - diff --git a/Tools/scripts/pyvenv b/Tools/scripts/pyvenv deleted file mode 100755 index 1fb42c639132a8..00000000000000 --- a/Tools/scripts/pyvenv +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python3 -if __name__ == '__main__': - import sys - import pathlib - - executable = pathlib.Path(sys.executable or 'python3').name - print('WARNING: the pyenv script is deprecated in favour of ' - f'`{executable} -m venv`', file=sys.stderr) - - rc = 1 - try: - import venv - venv.main() - rc = 0 - except Exception as e: - print('Error: %s' % e, file=sys.stderr) - sys.exit(rc) diff --git a/setup.py b/setup.py index 8536c350fe3a10..170ade81c4f80a 100644 --- a/setup.py +++ b/setup.py @@ -2291,7 +2291,7 @@ def copy_scripts(self): newoutfiles = [] newupdated_files = [] for filename in outfiles: - if filename.endswith(('2to3', 'pyvenv')): + if filename.endswith('2to3'): newfilename = filename + fullversion else: newfilename = filename + minoronly @@ -2359,7 +2359,7 @@ def main(): # check the PyBuildScripts command above, and change the links # created by the bininstall target in Makefile.pre.in scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", - "Tools/scripts/2to3", "Tools/scripts/pyvenv"] + "Tools/scripts/2to3"] ) # --install-platlib