Skip to content

Commit

Permalink
Merge branch 'main' into od_new
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored Aug 17, 2023
2 parents 4758750 + 5c76899 commit 4f04b7e
Show file tree
Hide file tree
Showing 22 changed files with 551 additions and 156 deletions.
71 changes: 36 additions & 35 deletions Doc/library/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ location), or only sequential access (for example in the case of a socket or
pipe).

All streams are careful about the type of data you give to them. For example
giving a :class:`str` object to the ``write()`` method of a binary stream
giving a :class:`str` object to the :meth:`!write` method of a binary stream
will raise a :exc:`TypeError`. So will giving a :class:`bytes` object to the
``write()`` method of a text stream.
:meth:`!write` method of a text stream.

.. versionchanged:: 3.3
Operations that used to raise :exc:`IOError` now raise :exc:`OSError`, since
Expand Down Expand Up @@ -146,7 +146,7 @@ Opt-in EncodingWarning
See :pep:`597` for more details.

To find where the default locale encoding is used, you can enable
the ``-X warn_default_encoding`` command line option or set the
the :option:`-X warn_default_encoding <-X>` command line option or set the
:envvar:`PYTHONWARNDEFAULTENCODING` environment variable, which will
emit an :exc:`EncodingWarning` when the default encoding is used.

Expand Down Expand Up @@ -175,7 +175,7 @@ High-level Module Interface
.. audit-event:: open path,mode,flags io.open

This function raises an :ref:`auditing event <auditing>` ``open`` with
arguments ``path``, ``mode`` and ``flags``. The ``mode`` and ``flags``
arguments *path*, *mode* and *flags*. The *mode* and *flags*
arguments may have been modified or inferred from the original call.


Expand All @@ -184,10 +184,10 @@ High-level Module Interface
Opens the provided file with mode ``'rb'``. This function should be used
when the intent is to treat the contents as executable code.

``path`` should be a :class:`str` and an absolute path.
*path* should be a :class:`str` and an absolute path.

The behavior of this function may be overridden by an earlier call to the
:c:func:`PyFile_SetOpenCodeHook`. However, assuming that ``path`` is a
:c:func:`PyFile_SetOpenCodeHook`. However, assuming that *path* is a
:class:`str` and an absolute path, ``open_code(path)`` should always behave
the same as ``open(path, 'rb')``. Overriding the behavior is intended for
additional validation or preprocessing of the file.
Expand Down Expand Up @@ -258,7 +258,7 @@ standard stream implementations.
The abstract base classes also provide default implementations of some
methods in order to help implementation of concrete stream classes. For
example, :class:`BufferedIOBase` provides unoptimized implementations of
:meth:`~IOBase.readinto` and :meth:`~IOBase.readline`.
:meth:`!readinto` and :meth:`!readline`.

At the top of the I/O hierarchy is the abstract base class :class:`IOBase`. It
defines the basic interface to a stream. Note, however, that there is no
Expand Down Expand Up @@ -320,8 +320,8 @@ I/O Base Classes
implementations represent a file that cannot be read, written or
seeked.

Even though :class:`IOBase` does not declare :meth:`read`
or :meth:`write` because their signatures will vary, implementations and
Even though :class:`IOBase` does not declare :meth:`!read`
or :meth:`!write` because their signatures will vary, implementations and
clients should consider those methods part of the interface. Also,
implementations may raise a :exc:`ValueError` (or :exc:`UnsupportedOperation`)
when operations they do not support are called.
Expand Down Expand Up @@ -379,8 +379,8 @@ I/O Base Classes

.. method:: readable()

Return ``True`` if the stream can be read from. If ``False``, :meth:`read`
will raise :exc:`OSError`.
Return ``True`` if the stream can be read from.
If ``False``, :meth:`!read` will raise :exc:`OSError`.

.. method:: readline(size=-1, /)

Expand All @@ -401,25 +401,25 @@ I/O Base Classes
hint.

Note that it's already possible to iterate on file objects using ``for
line in file: ...`` without calling ``file.readlines()``.
line in file: ...`` without calling :meth:`!file.readlines`.

.. method:: seek(offset, whence=SEEK_SET, /)

Change the stream position to the given byte *offset*. *offset* is
interpreted relative to the position indicated by *whence*. The default
value for *whence* is :data:`SEEK_SET`. Values for *whence* are:
value for *whence* is :data:`!SEEK_SET`. Values for *whence* are:

* :data:`SEEK_SET` or ``0`` -- start of the stream (the default);
* :data:`!SEEK_SET` or ``0`` -- start of the stream (the default);
*offset* should be zero or positive
* :data:`SEEK_CUR` or ``1`` -- current stream position; *offset* may
* :data:`!SEEK_CUR` or ``1`` -- current stream position; *offset* may
be negative
* :data:`SEEK_END` or ``2`` -- end of the stream; *offset* is usually
* :data:`!SEEK_END` or ``2`` -- end of the stream; *offset* is usually
negative

Return the new absolute position.

.. versionadded:: 3.1
The ``SEEK_*`` constants.
The :data:`!SEEK_*` constants.

.. versionadded:: 3.3
Some operating systems could support additional values, like
Expand Down Expand Up @@ -450,7 +450,7 @@ I/O Base Classes
.. method:: writable()

Return ``True`` if the stream supports writing. If ``False``,
:meth:`write` and :meth:`truncate` will raise :exc:`OSError`.
:meth:`!write` and :meth:`truncate` will raise :exc:`OSError`.

.. method:: writelines(lines, /)

Expand Down Expand Up @@ -654,8 +654,9 @@ Raw File I/O
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
``'+'`` to the mode to allow simultaneous reading and writing.

The :meth:`read` (when called with a positive argument), :meth:`readinto`
and :meth:`write` methods on this class will only make one system call.
The :meth:`~RawIOBase.read` (when called with a positive argument),
:meth:`~RawIOBase.readinto` and :meth:`~RawIOBase.write` methods on this
class will only make one system call.

A custom opener can be used by passing a callable as *opener*. The underlying
file descriptor for the file object is then obtained by calling *opener* with
Expand Down Expand Up @@ -791,8 +792,8 @@ than raw I/O does.
object under various conditions, including:

* when the buffer gets too small for all pending data;
* when :meth:`flush()` is called;
* when a :meth:`seek()` is requested (for :class:`BufferedRandom` objects);
* when :meth:`flush` is called;
* when a :meth:`~IOBase.seek` is requested (for :class:`BufferedRandom` objects);
* when the :class:`BufferedWriter` object is closed or destroyed.

The constructor creates a :class:`BufferedWriter` for the given writeable
Expand Down Expand Up @@ -826,8 +827,8 @@ than raw I/O does.
:data:`DEFAULT_BUFFER_SIZE`.

:class:`BufferedRandom` is capable of anything :class:`BufferedReader` or
:class:`BufferedWriter` can do. In addition, :meth:`seek` and :meth:`tell`
are guaranteed to be implemented.
:class:`BufferedWriter` can do. In addition, :meth:`~IOBase.seek` and
:meth:`~IOBase.tell` are guaranteed to be implemented.


.. class:: BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)
Expand Down Expand Up @@ -904,7 +905,7 @@ Text I/O

.. method:: readline(size=-1, /)

Read until newline or EOF and return a single ``str``. If the stream is
Read until newline or EOF and return a single :class:`str`. If the stream is
already at EOF, an empty string is returned.

If *size* is specified, at most *size* characters will be read.
Expand All @@ -913,22 +914,22 @@ Text I/O

Change the stream position to the given *offset*. Behaviour depends on
the *whence* parameter. The default value for *whence* is
:data:`SEEK_SET`.
:data:`!SEEK_SET`.

* :data:`SEEK_SET` or ``0``: seek from the start of the stream
* :data:`!SEEK_SET` or ``0``: seek from the start of the stream
(the default); *offset* must either be a number returned by
:meth:`TextIOBase.tell`, or zero. Any other *offset* value
produces undefined behaviour.
* :data:`SEEK_CUR` or ``1``: "seek" to the current position;
* :data:`!SEEK_CUR` or ``1``: "seek" to the current position;
*offset* must be zero, which is a no-operation (all other values
are unsupported).
* :data:`SEEK_END` or ``2``: seek to the end of the stream;
* :data:`!SEEK_END` or ``2``: seek to the end of the stream;
*offset* must be zero (all other values are unsupported).

Return the new absolute position as an opaque number.

.. versionadded:: 3.1
The ``SEEK_*`` constants.
The :data:`!SEEK_*` constants.

.. method:: tell()

Expand Down Expand Up @@ -988,10 +989,10 @@ Text I/O
takes place. If *newline* is any of the other legal values, any ``'\n'``
characters written are translated to the given string.

If *line_buffering* is ``True``, :meth:`flush` is implied when a call to
If *line_buffering* is ``True``, :meth:`~IOBase.flush` is implied when a call to
write contains a newline character or a carriage return.

If *write_through* is ``True``, calls to :meth:`write` are guaranteed
If *write_through* is ``True``, calls to :meth:`~BufferedIOBase.write` are guaranteed
not to be buffered: any data written on the :class:`TextIOWrapper`
object is immediately handled to its underlying binary *buffer*.

Expand Down Expand Up @@ -1070,7 +1071,7 @@ Text I/O

.. method:: getvalue()

Return a ``str`` containing the entire contents of the buffer.
Return a :class:`str` containing the entire contents of the buffer.
Newlines are decoded as if by :meth:`~TextIOBase.read`, although
the stream position is not changed.

Expand Down Expand Up @@ -1125,7 +1126,7 @@ Text I/O over a binary storage (such as a file) is significantly slower than
binary I/O over the same storage, because it requires conversions between
unicode and binary data using a character codec. This can become noticeable
handling huge amounts of text data like large log files. Also,
:meth:`TextIOWrapper.tell` and :meth:`TextIOWrapper.seek` are both quite slow
:meth:`~TextIOBase.tell` and :meth:`~TextIOBase.seek` are both quite slow
due to the reconstruction algorithm used.

:class:`StringIO`, however, is a native in-memory unicode container and will
Expand All @@ -1135,7 +1136,7 @@ Multi-threading
^^^^^^^^^^^^^^^

:class:`FileIO` objects are thread-safe to the extent that the operating system
calls (such as ``read(2)`` under Unix) they wrap are thread-safe too.
calls (such as :manpage:`read(2)` under Unix) they wrap are thread-safe too.

Binary buffered objects (instances of :class:`BufferedReader`,
:class:`BufferedWriter`, :class:`BufferedRandom` and :class:`BufferedRWPair`)
Expand Down
1 change: 0 additions & 1 deletion Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Doc/library/http.server.rst
Doc/library/importlib.resources.rst
Doc/library/importlib.rst
Doc/library/inspect.rst
Doc/library/io.rst
Doc/library/locale.rst
Doc/library/logging.config.rst
Doc/library/logging.handlers.rst
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *
PyObject *_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
PyObject *_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
int _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, PyObject **sp);
void _PyEval_FrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);


#ifdef __cplusplus
Expand Down
9 changes: 9 additions & 0 deletions Include/internal/pycore_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ extern PyObject* _PyFunction_Vectorcall(

#define FUNC_MAX_WATCHERS 8

#define FUNC_VERSION_CACHE_SIZE (1<<12) /* Must be a power of 2 */
struct _py_func_state {
uint32_t next_version;
// Borrowed references to function objects whose
// func_version % FUNC_VERSION_CACHE_SIZE
// once was equal to the index in the table.
// They are cleared when the function is deallocated.
PyFunctionObject *func_version_cache[FUNC_VERSION_CACHE_SIZE];
};

extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);

extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
extern void _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version);
PyFunctionObject *_PyFunction_LookupByVersion(uint32_t version);

extern PyObject *_Py_set_function_type_params(
PyThreadState* unused, PyObject *func, PyObject *type_params);

Expand Down
Loading

0 comments on commit 4f04b7e

Please sign in to comment.