8000 Merge branch 'master' of https://github.com/python/cpython into master · python/cpython@efa5de7 · GitHub
[go: up one dir, main page]

Skip to content

Commit efa5de7

Browse files
author
Ross Rhodes
committed
Merge branch 'master' of https://github.com/python/cpython into master
2 parents b09e617 + c56988b commit efa5de7

File tree

15 files changed

+128
-22
lines changed

15 files changed

+128
-22
lines changed

.github/problem-matchers/msvc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"__comment": "Taken from vscode's vs/workbench/contrib/tasks/common/problemMatcher.ts msCompile rule",
3+
"problemMatcher": [
4+
{
5+
"owner": "msvc-problem-matcher",
6+
"pattern": [
7+
{
8+
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+),?(\\d+)?(?:,\\d+,\\d+)?\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"severity": 4,
13+
"code": 5,
14+
"message": 6
15+
}
16+
]
17+
}
18+
]
19+
}

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ jobs:
9999
if: needs.check_source.outputs.run_tests == 'true'
100100
steps:
101101
- uses: actions/checkout@v2
102+
- name: Register MSVC problem matcher
103+
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
102104
- name: Build CPython
103105
run: .\PCbuild\build.bat -e -p x64
104106
- name: Display build info

Doc/library/email.headerregistry.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ variant, :attr:`~.BaseHeader.max_count` is set to 1.
289289
A :class:`ParameterizedMIMEHeader` class that handles the
290290
:mailheader:`Content-Disposition` header.
291291

292-
.. attribute:: content-disposition
292+
.. attribute:: content_disposition
293293

294294
``inline`` and ``attachment`` are the only valid values in common use.
295295

Doc/library/random.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ Functions for integers
135135
values. Formerly it used a style like ``int(random()*n)`` which could produce
136136
slightly uneven distributions.
137137

138+
.. deprecated:: 3.10
139+
The automatic conversion of non-integer types to equivalent integers is
140+
deprecated. Currently ``randrange(10.0)`` is losslessly converted to
141+
``randrange(10)``. In the future, this will raise a :exc:`TypeError`.
142+
143+
.. deprecated:: 3.10
144+
The exception raised for non-integral values such as ``range(10.5)``
145+
will be changed from :exc:`ValueError` to :exc:`TypeError`.
146+
138147
.. function:: randint(a, b)
139148

140149
Return a random integer *N* such that ``a <= N <= b``. Alias for

Doc/library/sqlite3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ Connection Objects
546546
con.close()
547547

548548

549-
.. method:: backup(target, *, pages=0, progress=None, name="main", sleep=0.250)
549+
.. method:: backup(target, *, pages=-1, progress=None, name="main", sleep=0.250)
550550

551551
This method makes a backup of a SQLite database even while it's being accessed
552552
by other clients, or concurrently by the same connection. The copy will be

Lib/random.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from math import tau as TWOPI, floor as _floor, isfinite as _isfinite
5252
from os import urandom as _urandom
5353
from _collections_abc import Set as _Set, Sequence as _Sequence
54+
from operator import index as _index
5455
from itertools import accumulate as _accumulate, repeat as _repeat
5556
from bisect import bisect as _bisect
5657
import os as _os
@@ -297,28 +298,59 @@ def randrange(self, start, stop=None, step=1):
297298

298299
# This code is a bit messy to make it fast for the
299300
# common case while still doing adequate error checking.
300-
istart = int(start)
301-
if istart != start:
302-
raise ValueError("non-integer arg 1 for randrange()")
301+
try:
302+
istart = _index(start)
303+
except TypeError:
304+
if int(start) == start:
305+
istart = int(start)
306+
_warn('Float arguments to randrange() have been deprecated\n'
307+
'since Python 3.10 and will be removed in a subsequent '
308+
'version.',
309+
DeprecationWarning, 2)
310+
else:
311+
_warn('randrange() will raise TypeError in the future',
312+
DeprecationWarning, 2)
313+
raise ValueError("non-integer arg 1 for randrange()")
303314
if stop is None:
304315
if istart > 0:
305316
return self._randbelow(istart)
306317
raise ValueError("empty range for randrange()")
307318

308319
# stop argument supplied.
309-
istop = int(stop)
310-
if istop != stop:
311-
raise ValueError("non-integer stop for randrange()")
320+
try:
321+
istop = _index(stop)
322+
except TypeError:
323+
if int(stop) == stop:
324+
istop = int(stop)
325+
_warn('Float arguments to randrange() have been deprecated\n'
326+
'since Python 3.10 and will be removed in a subsequent '
327+
'version.',
328+
DeprecationWarning, 2)
329+
else:
330+
_warn('randrange() will raise TypeError in the future',
331+
DeprecationWarning, 2)
332+
raise ValueError("non-integer stop for randrange()")
333+
334+
try:
335+
istep = _index(step)
336+
except TypeError:
337+
if int(step) == step:
338+
istep = int(step)
339+
_warn('Float arguments to randrange() have been deprecated\n'
340+
'since Python 3.10 and will be removed in a subsequent '
341+
'version.',
342+
DeprecationWarning, 2)
343+
else:
344+
_warn('randrange() will raise TypeError in the future',
345+
DeprecationWarning, 2)
346+
raise ValueError("non-integer step for randrange()")
312347
width = istop - istart
313-
if step == 1 and width > 0:
348+
if istep == 1 and width > 0:
314349
return istart + self._randbelow(width)
315-
if step == 1:
350+
if istep == 1:
316351
raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
317352

318353
# Non-unit step argument supplied.
319-
istep = int(step)
320-
if istep != step:
321-
raise ValueError("non-integer step for randrange()")
322354
if istep > 0:
323355
n = (width + istep - 1) // istep
324356
elif istep < 0:

Lib/test/test_random.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,26 @@ def test_randrange_errors(self):
542542
raises(0, 42, 0)
543543
raises(0, 42, 3.14159)
544544

545+
def test_randrange_argument_handling(self):
546+
randrange = self.gen.randrange
547+
with self.assertWarns(DeprecationWarning):
548+
randrange(10.0, 20, 2)
549+
with self.assertWarns(DeprecationWarning):
550+
randrange(10, 20.0, 2)
551+
with self.assertWarns(DeprecationWarning):
552+
randrange(10, 20, 1.0)
553+
with self.assertWarns(DeprecationWarning):
554+
randrange(10, 20, 2.0)
555+
with self.assertWarns(DeprecationWarning):
556+
F438 with self.assertRaises(ValueError):
557+
randrange(10.5)
558+
with self.assertWarns(DeprecationWarning):
559+
with self.assertRaises(ValueError):
560+
randrange(10, 20.5)
561+
with self.assertWarns(DeprecationWarning):
562+
with self.assertRaises(ValueError):
563+
randrange(10, 20, 1.5)
564+
545565
def test_randbelow_logic(self, _log=log, int=int):
546566
# check bitcount transition points: 2**i and 2**(i+1)-1
547567
# show that: k = int(1.001 + _log(n, 2))

Lib/test/test_typing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,7 @@ class C(Generic[T]): pass
30213021
self.assertIs(get_origin(Callable), collections.abc.Callable)
30223022
self.assertIs(get_origin(list[int]), list)
30233023
self.assertIs(get_origin(list), None)
3024+
self.assertIs(get_origin(list | str), types.Union)
30243025

30253026
def test_get_args(self):
30263027
T = TypeVar('T')
@@ -3048,6 +3049,16 @@ class C(Generic[T]): pass
30483049
self.assertEqual(get_args(Callable), ())
30493050
self.assertEqual(get_args(list[int]), (int,))
30503051
self.assertEqual(get_args(list), ())
3052+
self.assertEqual(get_args(collections.abc.Callable[[int], str]), ([int], str))
3053+
self.assertEqual(get_args(collections.abc.Callable[..., str]), (..., str))
3054+
self.assertEqual(get_args(collections.abc.Callable[[], str]), ([], str))
3055+
self.assertEqual(get_args(collections.abc.Callable[[int], str]),
3056+
get_args(Callable[[int], str]))
3057+
P = ParamSpec('P')
3058+
self.assertEqual(get_args(Callable[P, int]), (P, int))
3059+
self.assertEqual(get_args(Callable[Concatenate[int, P], int]),
3060+
(Concatenate[int, P], int))
3061+
self.assertEqual(get_args(list | str), (list, str))
30513062

30523063

30533064
class CollectionsAbcTests(BaseTestCase):

Lib/typing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,8 @@ def get_origin(tp):
16681668
return tp.__origin__
16691669
if tp is Generic:
16701670
return Generic
1671+
if isinstance(tp, types.Union):
1672+
return types.Union
16711673
return None
16721674

16731675

@@ -1684,12 +1686,14 @@ def get_args(tp):
16841686
"""
16851687
if isinstance(tp, _AnnotatedAlias):
16861688
return (tp.__origin__,) + tp.__metadata__
1687-
if isinstance(tp, _GenericAlias):
1689+
if isinstance(tp, (_GenericAlias, GenericAlias)):
16881690
res = tp.__args__
1689-
if tp.__origin__ is collections.abc.Callable and res[0] is not Ellipsis:
1691+
if (tp.__origin__ is collections.abc.Callable
1692+
and not (res[0] is Ellipsis
1693+
or isinstance(res[0], (ParamSpec, _ConcatenateGenericAlias)))):
16901694
res = (list(res[:-1]), res[-1])
16911695
return res
1692-
if isinstance(tp, GenericAlias):
1696+
if isinstance(tp, types.Union):
16931697
return tp.__args__
16941698
return ()
16951699

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Harmonized random.randrange() argument handling to match range().
2+
3+
* The integer test and conversion in randrange() now uses
4+
operator.index().
5+
* Non-integer arguments to randrange() are deprecated.
6+
* The *ValueError* is deprecated in favor of a *TypeError*.
7+
* It now runs a little faster than before.
8+
9+
(Contributed by Raymond Hettinger and Serhiy Storchaka.)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`typing.get_args` and :func:`typing.get_origin` now support :pep:`604`
2+
union types and :pep:`612` additions to ``Callable``.

Modules/_queuemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ simplequeue_get_state(PyObject *module)
1515
return state;
1616
}
1717
static struct PyModuleDef queuemodule;
18-
#define simplequeue_get_state_by_type(tp) \
18+
#define simplequeue_get_state_by_type(type) \
1919
(simplequeue_get_state(_PyType_GetModuleByDef(type, &queuemodule)))
2020

2121
typedef struct {

Modules/_sqlite/connection.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
891891
return NULL;
892892
}
893893

894-
Py_INCREF(aggregate_class);
895894
rc = sqlite3_create_function_v2(self->db,
896895
name,
897896
n_arg,
@@ -1602,7 +1601,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
16021601
{
16031602
int rc;
16041603
int callback_error = 0;
1605-
int sleep_ms = sleep * 1000.0;
1604+
int sleep_ms = (int)(sleep * 1000.0);
16061605
sqlite3 *bck_conn;
16071606
sqlite3_backup *bck_handle;
16081607

Modules/_struct.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,7 @@ s_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14421442
self = alloc_func(type, 0);
14431443
if (self != NULL) {
14441444
PyStructObject *s = (PyStructObject*)self;
1445-
Py_INCREF(Py_None);
1446-
s->s_format = Py_None;
1445+
s->s_format = Py_NewRef(Py_None);
14471446
s->s_codes = NULL;
14481447
s->s_size = -1;
14491448
s->s_len = -1;

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ _PyUnicode_FromId(_Py_Identifier *id)
23022302
PyInterpreterState *interp = _PyInterpreterState_GET();
23032303
struct _Py_unicode_ids *ids = &interp->unicode.ids;
23042304

2305-
int index = _Py_atomic_size_get(&id->index);
2305+
Py_ssize_t index = _Py_atomic_size_get(&id->index);
23062306
if (index < 0) {
23072307
struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_ids;
23082308

0 commit comments

Comments
 (0)
0