Skip to content

bpo-37319: Deprecated support of non-integer arguments in random.randrange(). #19112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Merge branch 'master' into randrange-index
  • Loading branch information
serhiy-storchaka committed Jan 24, 2021
commit d5dec67d02850d2ecc0441514ebd421bf62b07af
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Check for source changes
id: check
run: |
if [ -z "GITHUB_BASE_REF" ]; then
if [ -z "$GITHUB_BASE_REF" ]; then
echo '::set-output name=run_tests::true'
else
git fetch origin $GITHUB_BASE_REF --depth=1
Expand Down Expand Up @@ -63,6 +63,7 @@ jobs:
# Build Python with the libpython dynamic library
./configure --with-pydebug --enable-shared
make -j4 regen-all
make regen-module-names
- name: Check for changes
run: |
changes=$(git status --porcelain)
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ before_script:
- eval "$(pyenv init -)"
- pyenv global 3.8
- PYTHON_FOR_REGEN=python3.8 make -j4 regen-all
- make regen-module-names
- changes=`git status --porcelain`
- |
# Check for changes in regenerated files
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/bool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ are available, however.

.. c:function:: int PyBool_Check(PyObject *o)

Return true if *o* is of type :c:data:`PyBool_Type`.
Return true if *o* is of type :c:data:`PyBool_Type`. This function always
succeeds.


.. c:var:: PyObject* Py_False
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/bytearray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ Type check macros
.. c:function:: int PyByteArray_Check(PyObject *o)

Return true if the object *o* is a bytearray object or an instance of a
subtype of the bytearray type.
subtype of the bytearray type. This function always succeeds.


.. c:function:: int PyByteArray_CheckExact(PyObject *o)

Return true if the object *o* is a bytearray object, but not an instance of a
subtype of the bytearray type.
subtype of the bytearray type. This function always succeeds.


Direct API functions
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/bytes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ called with a non-bytes parameter.
.. c:function:: int PyBytes_Check(PyObject *o)

Return true if the object *o* is a bytes object or an instance of a subtype
of the bytes type.
of the bytes type. This function always succeeds.


.. c:function:: int PyBytes_CheckExact(PyObject *o)

Return true if the object *o* is a bytes object, but not an instance of a
subtype of the bytes type.
subtype of the bytes type. This function always succeeds.


.. c:function:: PyObject* PyBytes_FromString(const char *v)
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/capsule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Refer to :ref:`using-capsules` for more information on using these objects.

.. c:function:: int PyCapsule_CheckExact(PyObject *p)

Return true if its argument is a :c:type:`PyCapsule`.
Return true if its argument is a :c:type:`PyCapsule`. This function always
succeeds.


.. c:function:: PyObject* PyCapsule_New(void *pointer, const char *name, PyCapsule_Destructor destructor)
Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/cell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Cell objects are not likely to be useful elsewhere.

.. c:function:: int PyCell_Check(ob)

Return true if *ob* is a cell object; *ob* must not be ``NULL``.
Return true if *ob* is a cell object; *ob* must not be ``NULL``. This
function always succeeds.


.. c:function:: PyObject* PyCell_New(PyObject *ob)
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bound into a function.

.. c:function:: int PyCode_Check(PyObject *co)

Return true if *co* is a :class:`code` object.
Return true if *co* is a :class:`code` object. This function always succeeds.

.. c:function:: int PyCode_GetNumFree(PyCodeObject *co)

Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ Complex Numbers as Python Objects
.. c:function:: int PyComplex_Check(PyObject *p)

Return true if its argument is a :c:type:`PyComplexObject` or a subtype of
:c:type:`PyComplexObject`.
:c:type:`PyComplexObject`. This function always succeeds.


.. c:function:: int PyComplex_CheckExact(PyObject *p)

Return true if its argument is a :c:type:`PyComplexObject`, but not a subtype of
:c:type:`PyComplexObject`.
:c:type:`PyComplexObject`. This function always succeeds.


.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)
Expand Down
1 change: 1 addition & 0 deletions Doc/c-api/coro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ return.
.. c:function:: int PyCoro_CheckExact(PyObject *ob)

Return true if *ob*'s type is :c:type:`PyCoro_Type`; *ob* must not be ``NULL``.
This function always succeeds.


.. c:function:: PyObject* PyCoro_New(PyFrameObject *frame, PyObject *name, PyObject *qualname)
Expand Down
25 changes: 15 additions & 10 deletions Doc/c-api/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,66 @@ Type-check macros:
.. c:function:: int PyDate_Check(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DateType` or a subtype of
:c:data:`PyDateTime_DateType`. *ob* must not be ``NULL``.
:c:data:`PyDateTime_DateType`. *ob* must not be ``NULL``. This function always
succeeds.


.. c:function:: int PyDate_CheckExact(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DateType`. *ob* must not be
``NULL``.
``NULL``. This function always succeeds.


.. c:function:: int PyDateTime_Check(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType` or a subtype of
:c:data:`PyDateTime_DateTimeType`. *ob* must not be ``NULL``.
:c:data:`PyDateTime_DateTimeType`. *ob* must not be ``NULL``. This function always
succeeds.


.. c:function:: int PyDateTime_CheckExact(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DateTimeType`. *ob* must not
be ``NULL``.
be ``NULL``. This function always succeeds.


.. c:function:: int PyTime_Check(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_TimeType` or a subtype of
:c:data:`PyDateTime_TimeType`. *ob* must not be ``NULL``.
:c:data:`PyDateTime_TimeType`. *ob* must not be ``NULL``. This function always
succeeds.


.. c:function:: int PyTime_CheckExact(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_TimeType`. *ob* must not be
``NULL``.
``NULL``. This function always succeeds.


.. c:function:: int PyDelta_Check(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DeltaType` or a subtype of
:c:data:`PyDateTime_DeltaType`. *ob* must not be ``NULL``.
:c:data:`PyDateTime_DeltaType`. *ob* must not be ``NULL``. This function always
succeeds.


.. c:function:: int PyDelta_CheckExact(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_DeltaType`. *ob* must not be
``NULL``.
``NULL``. This function always succeeds.


.. c:function:: int PyTZInfo_Check(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType` or a subtype of
:c:data:`PyDateTime_TZInfoType`. *ob* must not be ``NULL``.
:c:data:`PyDateTime_TZInfoType`. *ob* must not be ``NULL``. This function always
succeeds.


.. c:function:: int PyTZInfo_CheckExact(PyObject *ob)

Return true if *ob* is of type :c:data:`PyDateTime_TZInfoType`. *ob* must not be
``NULL``.
``NULL``. This function always succeeds.


Macros to create objects:
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Dictionary Objects
.. c:function:: int PyDict_Check(PyObject *p)

Return true if *p* is a dict object or an instance of a subtype of the dict
type.
type. This function always succeeds.


.. c:function:: int PyDict_CheckExact(PyObject *p)

Return true if *p* is a dict object, but not an instance of a subtype of
the dict type.
the dict type. This function always succeeds.


.. c:function:: PyObject* PyDict_New()
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/float.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Floating Point Objects
.. c:function:: int PyFloat_Check(PyObject *p)

Return true if its argument is a :c:type:`PyFloatObject` or a subtype of
:c:type:`PyFloatObject`.
:c:type:`PyFloatObject`. This function always succeeds.


.. c:function:: int PyFloat_CheckExact(PyObject *p)

Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of
:c:type:`PyFloatObject`.
:c:type:`PyFloatObject`. This function always succeeds.


.. c:function:: PyObject* PyFloat_FromString(PyObject *str)
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ There are a few functions specific to Python functions.
.. c:function:: int PyFunction_Check(PyObject *o)

Return true if *o* is a function object (has type :c:data:`PyFunction_Type`).
The parameter must not be ``NULL``.
The parameter must not be ``NULL``. This function always succeeds.


.. c:function:: PyObject* PyFunction_New(PyObject *code, PyObject *globals)
Expand Down
6 changes: 4 additions & 2 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.

.. c:function:: int PyGen_Check(PyObject *ob)

Return true if *ob* is a generator object; *ob* must not be ``NULL``.
Return true if *ob* is a generator object; *ob* must not be ``NULL``. This
function always succeeds.


.. c:function:: int PyGen_CheckExact(PyObject *ob)

Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be ``NULL``.
Return true if *ob*'s type is :c:type:`PyGen_Type`; *ob* must not be
``NULL``. This function always succeeds.


.. c:function:: PyObject* PyGen_New(PyFrameObject *frame)
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

.. versionadded:: 3.9

.. c:function:: void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, _PyFrameEvalFunction eval_frame);
.. c:function:: void _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp, _PyFrameEvalFunction eval_frame)

Set the frame evaluation function.

Expand Down
3 changes: 2 additions & 1 deletion Doc/c-api/iter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ There are two functions specifically for working with iterators.

.. c:function:: int PyIter_Check(PyObject *o)

Return true if the object *o* supports the iterator protocol.
Return true if the object *o* supports the iterator protocol. This
function always succeeds.


.. c:function:: PyObject* PyIter_Next(PyObject *o)
Expand Down
6 changes: 4 additions & 2 deletions Doc/c-api/iterator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ sentinel value is returned.

.. c:function:: int PySeqIter_Check(op)

Return true if the type of *op* is :c:data:`PySeqIter_Type`.
Return true if the type of *op* is :c:data:`PySeqIter_Type`. This function
always succeeds.


.. c:function:: PyObject* PySeqIter_New(PyObject *seq)
Expand All @@ -39,7 +40,8 @@ sentinel value is returned.

.. c:function:: int PyCallIter_Check(op)

Return true if the type of *op* is :c:data:`PyCallIter_Type`.
Return true if the type of *op* is :c:data:`PyCallIter_Type`. This
function always succeeds.


.. c:function:: PyObject* PyCallIter_New(PyObject *callable, PyObject *sentinel)
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ List Objects
.. c:function:: int PyList_Check(PyObject *p)

Return true if *p* is a list object or an instance of a subtype of the list
type.
type. This function always succeeds.


.. c:function:: int PyList_CheckExact(PyObject *p)

Return true if *p* is a list object, but not an instance of a subtype of
the list type.
the list type. This function always succeeds.


.. c:function:: PyObject* PyList_New(Py_ssize_t len)
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
.. c:function:: int PyLong_Check(PyObject *p)

Return true if its argument is a :c:type:`PyLongObject` or a subtype of
:c:type:`PyLongObject`.
:c:type:`PyLongObject`. This function always succeeds.


.. c:function:: int PyLong_CheckExact(PyObject *p)

Return true if its argument is a :c:type:`PyLongObject`, but not a subtype of
:c:type:`PyLongObject`.
:c:type:`PyLongObject`. This function always succeeds.


.. c:function:: PyObject* PyLong_FromLong(long v)
Expand Down
40 changes: 39 additions & 1 deletion Doc/c-api/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ for the I/O buffer escapes completely the Python memory manager.
statistics of the :ref:`pymalloc memory allocator <pymalloc>` every time a
new pymalloc object arena is created, and on shutdown.

Allocator Domains
=================

All allocating functions belong to one of three different "domains" (see also
:c:type`PyMemAllocatorDomain`). These domains represent different allocation
strategies and are optimized for different purposes. The specific details on
how every domain allocates memory or what internal functions each domain calls
is considered an implementation detail, but for debugging purposes a simplified
table can be found at :ref:`here <default-memory-allocators>`. There is no hard
requirement to use the memory returned by the allocation functions belonging to
a given domain for only the purposes hinted by that domain (although this is the
recommended practice). For example, one could use the memory returned by
:c:func:`PyMem_RawMalloc` for allocating Python objects or the memory returned
by :c:func:`PyObject_Malloc` for allocating memory for buffers.

The three allocation domains are:

* Raw domain: intended for allocating memory for general-purpose memory
buffers where the allocation *must* go to the system allocator or where the
allocator can operate without the :term:`GIL`. The memory is requested directly
to the system.

* "Mem" domain: intended for allocating memory for Python buffers and
general-purpose memory buffers where the allocation must be performed with
the :term:`GIL` held. The memory is taken from the Python private heap.

* Object domain: intended for allocating memory belonging to Python objects. The
memory is taken from the Python private heap.

When freeing memory previously allocated by the allocating functions belonging to a
given domain,the matching specific deallocating functions must be used. For example,
:c:func:`PyMem_Free` must be used to free memory allocated using :c:func:`PyMem_Malloc`.

Raw Memory Interface
====================
Expand Down Expand Up @@ -272,6 +304,12 @@ The following function sets, modeled after the ANSI C standard, but specifying
behavior when requesting zero bytes, are available for allocating and releasing
memory from the Python heap.

.. note::
There is no guarantee that the memory returned by these allocators can be
succesfully casted to a Python object when intercepting the allocating
functions in this domain by the methods described in
the :ref:`Customize Memory Allocators <customize-memory-allocators>` section.

The :ref:`default object allocator <default-memory-allocators>` uses the
:ref:`pymalloc memory allocator <pymalloc>`.

Expand Down Expand Up @@ -353,6 +391,7 @@ Legend:
* ``pymalloc``: :ref:`pymalloc memory allocator <pymalloc>`
* "+ debug": with debug hooks installed by :c:func:`PyMem_SetupDebugHooks`

.. _customize-memory-allocators:

Customize Memory Allocators
===========================
Expand Down Expand Up @@ -601,4 +640,3 @@ heap, objects in Python are allocated and released with :c:func:`PyObject_New`,

These will be explained in the next chapter on defining and implementing new
object types in C.

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.