8000 Merge branch 'main' into cached-strs · python/cpython@f2f0327 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2f0327

Browse files
Merge branch 'main' into cached-strs
2 parents 0a76abd + be09bae commit f2f0327

36 files changed

+1331
-314
lines changed

Doc/library/ast.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Node classes
4545

4646
This is the base of all AST node classes. The actual node classes are
4747
derived from the :file:`Parser/Python.asdl` file, which is reproduced
48-
:ref:`below <abstract-grammar>`. They are defined in the :mod:`_ast` C
48+
:ref:`above <abstract-grammar>`. They are defined in the :mod:`_ast` C
4949
module and re-exported in :mod:`ast`.
5050

5151
There is one class defined for each left-hand side symbol in the abstract
@@ -1951,7 +1951,7 @@ and classes for traversing abstract syntax trees:
19511951

19521952
If source contains a null character ('\0'), :exc:`ValueError` is raised.
19531953

1954-
.. warning::
1954+
.. warning::
19551955
Note that successfully parsing source code into an AST object doesn't
19561956
guarantee that the source code provided is valid Python code that can
19571957
be executed as the compilation step can raise further :exc:`SyntaxError`

Doc/library/datetime.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ Instance methods:
13701370
time and this method relies on the platform C :c:func:`mktime`
13711371
function to perform the conversion. Since :class:`.datetime`
13721372
supports wider range of values than :c:func:`mktime` on many
1373-
platforms, this method may raise :exc:`OverflowError` for times far
1374-
in the past or far in the future.
1373+
platforms, this method may raise :exc:`OverflowError` or :exc:`OSError`
1374+
for times far in the past or far in the future.
13751375

13761376
For aware :class:`.datetime` instances, the return value is computed
13771377
as::

Doc/library/dis.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,6 @@ iterations of the loop.
604604
.. versionchanged:: 3.11
605605
oparg set to be the stack depth, for efficient handling on frames.
606606

607-
.. opcode:: YIELD_FROM
608-
609-
Pops TOS and delegates to it as a subiterator from a :term:`generator`.
610-
611-
.. versionadded:: 3.3
612-
613607

614608
.. opcode:: SETUP_ANNOTATIONS
615609

Grammar/python.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ for_stmt[stmt_ty]:
391391
with_stmt[stmt_ty]:
392392
| invalid_with_stmt_indent
393393
| 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
394-
_PyAST_With(a, b, NULL, EXTRA) }
394+
CHECK_VERSION(stmt_ty, 9, "Parenthesized context managers are", _PyAST_With(a, b, NULL, EXTRA)) }
395395
| 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
396396
_PyAST_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
397397
| ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {

Include/internal/pycore_code.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ read_obj(uint16_t *p)
390390
return (PyObject *)val;
391391
}
392392

393+
/* See Objects/exception_handling_notes.txt for details.
394+
*/
395+
static inline unsigned char *
396+
parse_varint(unsigned char *p, int *result) {
397+
int val = p[0] & 63;
398+
while (p[0] & 64) {
399+
p++;
400+
val = (val << 6) | (p[0] & 63);
401+
}
402+
*result = val;
403+
return p+1;
404+
}
405+
393406
static inline int
394407
write_varint(uint8_t *ptr, unsigned int val)
395408
{

Lib/enum.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,6 @@ def __new__(cls, value):
11121112
def __init__(self, *args, **kwds):
11131113
pass
11141114

1115-
def __getattribute__(self, name):
1116-
self_dict = super().__getattribute__('__dict__')
1117-
cls = super().__getattribute__('__class__')
1118-
value = super().__getattribute__(name)
1119-
if isinstance(value, cls) and name not in self_dict and name in self._member_names_:
1120-
raise AttributeError("<enum '%s'> member has no attribute %r" % (cls.__name__, name))
1121-
return super().__getattribute__(name)
1122-
11231115
def _generate_next_value_(name, start, count, last_values):
11241116
"""
11251117
Generate the next value when not given.

Lib/test/test_ast.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ def test_ast_asdl_signature(self):
738738
expressions[0] = f"expr = {ast.expr.__subclasses__()[0].__doc__}"
739739
self.assertCountEqual(ast.expr.__doc__.split("\n"), expressions)
740740

741+
def test_parenthesized_with_feature_version(self):
742+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 10))
743+
# While advertised as a feature in Python 3.10, this was allowed starting 3.9
744+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 9))
745+
with self.assertRaises(SyntaxError):
746+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 8))
747+
ast.parse('with CtxManager() as example: ...', feature_version=(3, 8))
748+
741749
def test_issue40614_feature_version(self):
742750
ast.parse('f"{x=}"', feature_version=(3, 8))
743751
with self.assertRaises(SyntaxError):

Lib/test/test_bytes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,23 @@ def test_repeat_after_setslice(self):
17101710
self.assertEqual(b1, b)
17111711
self.assertEqual(b3, b'xcxcxc')
17121712

1713+
def test_mutating_index(self):
1714+
class Boom:
1715+
def __index__(self):
1716+
b.clear()
1717+
return 0
1718+
1719+
with self.subTest("tp_as_mapping"):
1720+
b = bytearray(b'Now you see me...')
1721+
with self.assertRaises(IndexError):
1722+
b[0] = Boom()
1723+
1724+
with self.subTest("tp_as_sequence"):
1725+
_testcapi = import_helper.import_module('_testcapi')
1726+
b = bytearray(b'Now you see me...')
1727+
with self.assertRaises(IndexError):
1728+
_testcapi.sequence_setitem(b, 0, Boom())
1729+
17131730

17141731
class AssortedBytesTest(unittest.TestCase):
17151732
#

Lib/test/test_code.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
freevars: ()
1818
nlocals: 2
1919
flags: 3
20-
lnotab: [4, 1, 10, 2]
2120
consts: ('None', '<code object g>')
2221
2322
>>> dump(f(4).__code__)
@@ -31,7 +30,6 @@
3130
freevars: ('x',)
3231
nlocals: 1
3332
flags: 19
34-
lnotab: [4, 1]
3533
consts: ('None',)
3634
3735
>>> def h(x, y):
@@ -52,7 +50,6 @@
5250
freevars: ()
5351
nlocals: 5
5452
flags: 3
55-
lnotab: [2, 1, 10, 1, 10, 1, 10, 1]
5653
consts: ('None',)
5754
5855
>>> def attrs(obj):
@@ -71,7 +68,6 @@
7168
freevars: ()
7269
nlocals: 1
7370
flags: 3
74-
lnotab: [2, 1, 46, 1, 46, 1]
7571
consts: ('None',)
7672
7773
>>> def optimize_away():
@@ -91,7 +87,6 @@
9187
freevars: ()
9288
nlocals: 0
9389
flags: 3
94-
lnotab: [2, 2, 2, 1, 2, 1]
9590
consts: ("'doc string'", 'None')
9691
9792
>>> def keywordonly_args(a,b,*,k1):
@@ -109,7 +104,6 @@
109104
freevars: ()
110105
nlocals: 3
111106
flags: 3
112-
lnotab: [2, 1]
113107
consts: ('None',)
114108
115109
>>> def posonly_args(a,b,/,c):
@@ -127,7 +121,6 @@
127121
freevars: ()
128122
nlocals: 3
129123
flags: 3
130-
lnotab: [2, 1]
131124
consts: ('None',)
132125
133126
"""
@@ -168,7 +161,6 @@ def dump(co):
168161
"kwonlyargcount", "names", "varnames",
169162
"cellvars", "freevars", "nlocals", "flags"]:
170163
print("%s: %s" % (attr, getattr(co, "co_" + attr)))
171-
print("lnotab:", list(co.co_lnotab))
172164
print("consts:", tuple(consts(co.co_consts)))
173165

174166
# Needed for test_closure_injection below
@@ -436,21 +428,6 @@ def func():
436428
self.assertIsNone(line)
437429
self.assertEqual(end_line, new_code.co_firstlineno + 1)
438430

439-
def test_large_lnotab(self):
440-
d = {}
441-
lines = (
442-
["def f():"] +
443-
[""] * (1 << 17) +
444-
[" pass"] * (1 << 17)
445-
)
446-
source = "\n".join(lines)
447-
exec(source, d)
448-
code = d["f"].__code__
449-
450-
expected = 1032 * [0, 127] + [0, 9] + ((1 << 17) - 1) * [2, 1]
451-
expected[0] = 2
452-
self.assertEqual(list(code.co_lnotab), expected)
453-
454431

455432
def isinterned(s):
456433
return s is sys.intern(('_' + s + '_')[1:-1])

Lib/test/test_concurrent_futures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def test_cancel_futures_wait_false(self):
485485
t = ThreadPoolExecutor()
486486
t.submit(sleep_and_print, .1, "apple")
487487
t.shutdown(wait=False, cancel_futures=True)
488-
""".format(executor_type=self.executor_type.__name__))
488+
""")
489489
# Errors in atexit hooks don't change the process exit code, check
490490
# stderr manually.
491491
self.assertFalse(err)

Lib/test/test_enum.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,19 +2646,14 @@ class Private(Enum):
26462646
self.assertEqual(Private._Private__corporal, 'Radar')
26472647
self.assertEqual(Private._Private__major_, 'Hoolihan')
26482648

2649+
@unittest.skip("Accessing all values retained for performance reasons, see GH-93910")
26492650
def test_exception_for_member_from_member_access(self):
26502651
with self.assertRaisesRegex(AttributeError, "<enum .Di.> member has no attribute .NO."):
26512652
class Di(Enum):
26522653
YES = 1
26532654
NO = 0
26542655
nope = Di.YES.NO
26552656

2656-
def test_no_exception_for_overridden_member_from_member_access(self):
2657-
class Di(Enum):
2658-
YES = 1
2659-
NO = 0
2660-
Di.YES.NO = Di.NO
2661-
nope = Di.YES.NO
26622657

26632658
def test_dynamic_members_with_static_methods(self):
26642659
#

Lib/test/test_getargs2.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,19 @@ def test_s_hash(self):
877877
def test_s_hash_int(self):
878878
# "s#" without PY_SSIZE_T_CLEAN defined.
879879
from _testcapi import getargs_s_hash_int
880-
self.assertRaises(SystemError, getargs_s_hash_int, "abc")
881-
self.assertRaises(SystemError, getargs_s_hash_int, x=42)
882-
# getargs_s_hash_int() don't raise SystemError because skipitem() is not called.
880+
from _testcapi import getargs_s_hash_int2
881+
buf = bytearray([1, 2])
882+
self.assertRaises(SystemError, getargs_s_hash_int, buf, "abc")
883+
self.assertRaises(SystemError, getargs_s_hash_int, buf, x=42)
884+
self.assertRaises(SystemError, getargs_s_hash_int, buf, x="abc")
885+
self.assertRaises(SystemError, getargs_s_hash_int2, buf, ("abc",))
886+
self.assertRaises(SystemError, getargs_s_hash_int2, buf, x=42)
887+
self.assertRaises(SystemError, getargs_s_hash_int2, buf, x="abc")
888+
buf.append(3) # still mutable -- not locked by a buffer export
889+
# getargs_s_hash_int(buf) may not raise SystemError because skipitem()
890+
# is not called. But it is an implementation detail.
891+
# getargs_s_hash_int(buf)
892+
# getargs_s_hash_int2(buf)
883893

884894
def test_z(self):
885895
from _testcapi import getargs_z

0 commit comments

Comments
 (0)
0