Skip to content

Commit a2cff24

Browse files
Merge branch 'main' into gh-100926-ctypes-pointers-cache
2 parents 5768347 + 898e6b3 commit a2cff24

43 files changed

Lines changed: 712 additions & 139 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Include/internal/pycore_compile.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ void _PyCompile_ExitScope(struct _PyCompiler *c);
134134
Py_ssize_t _PyCompile_AddConst(struct _PyCompiler *c, PyObject *o);
135135
_PyInstructionSequence *_PyCompile_InstrSequence(struct _PyCompiler *c);
136136
int _PyCompile_FutureFeatures(struct _PyCompiler *c);
137-
PyObject *_PyCompile_DeferredAnnotations(struct _PyCompiler *c);
137+
void _PyCompile_DeferredAnnotations(
138+
struct _PyCompiler *c, PyObject **deferred_annotations,
139+
PyObject **conditional_annotation_indices);
138140
PyObject *_PyCompile_Mangle(struct _PyCompiler *c, PyObject *name);
139141
PyObject *_PyCompile_MaybeMangle(struct _PyCompiler *c, PyObject *name);
140142
int _PyCompile_MaybeAddStaticAttributeToClass(struct _PyCompiler *c, expr_ty e);
@@ -178,13 +180,16 @@ int _PyCompile_TweakInlinedComprehensionScopes(struct _PyCompiler *c, _Py_Source
178180
_PyCompile_InlinedComprehensionState *state);
179181
int _PyCompile_RevertInlinedComprehensionScopes(struct _PyCompiler *c, _Py_SourceLocation loc,
180182
_PyCompile_InlinedComprehensionState *state);
181-
int _PyCompile_AddDeferredAnnotaion(struct _PyCompiler *c, stmt_ty s);
183+
int _PyCompile_AddDeferredAnnotation(struct _PyCompiler *c, stmt_ty s,
184+
PyObject **conditional_annotation_index);
185+
void _PyCompile_EnterConditionalBlock(struct _PyCompiler *c);
186+
void _PyCompile_LeaveConditionalBlock(struct _PyCompiler *c);
182187

183188
int _PyCodegen_AddReturnAtEnd(struct _PyCompiler *c, int addNone);
184189
int _PyCodegen_EnterAnonymousScope(struct _PyCompiler* c, mod_ty mod);
185190
int _PyCodegen_Expression(struct _PyCompiler *c, expr_ty e);
186-
int _PyCodegen_Body(struct _PyCompiler *c, _Py_SourceLocation loc, asdl_stmt_seq *stmts,
187-
bool is_interactive);
191+
int _PyCodegen_Module(struct _PyCompiler *c, _Py_SourceLocation loc, asdl_stmt_seq *stmts,
192+
bool is_interactive);
188193

189194
int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);
190195

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct _Py_global_strings {
9595
STRUCT_FOR_ID(__classdict__)
9696
STRUCT_FOR_ID(__classdictcell__)
9797
STRUCT_FOR_ID(__complex__)
98+
STRUCT_FOR_ID(__conditional_annotations__)
9899
STRUCT_FOR_ID(__contains__)
99100
STRUCT_FOR_ID(__ctypes_from_outparam__)
100101
STRUCT_FOR_ID(__del__)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_symtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ typedef struct _symtable_entry {
124124
enclosing class scope */
125125
unsigned ste_has_docstring : 1; /* true if docstring present */
126126
unsigned ste_method : 1; /* true if block is a function block defined in class scope */
127+
unsigned ste_has_conditional_annotations : 1; /* true if block has conditionally executed annotations */
128+
unsigned ste_in_conditional_block : 1; /* set while we are inside a conditionally executed block */
127129
int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
128130
_Py_SourceLocation ste_loc; /* source location of block */
129131
struct _symtable_entry *ste_annotation_block; /* symbol table entry for this entry's annotations */

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_asyncgen.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,26 @@ async def run():
11691169

11701170
self.loop.run_until_complete(run())
11711171

1172+
def test_sync_anext_raises_exception(self):
1173+
# See: https://github.com/python/cpython/issues/131670
1174+
msg = 'custom'
1175+
for exc_type in [
1176+
StopAsyncIteration,
1177+
StopIteration,
1178+
ValueError,
1179+
Exception,
1180+
]:
1181+
exc = exc_type(msg)
1182+
with self.subTest(exc=exc):
1183+
class A:
1184+
def __anext__(self):
1185+
raise exc
1186+
1187+
with self.assertRaisesRegex(exc_type, msg):
1188+
anext(A())
1189+
with self.assertRaisesRegex(exc_type, msg):
1190+
anext(A(), 1)
1191+
11721192
def test_async_gen_asyncio_anext_stopiteration(self):
11731193
async def foo():
11741194
try:

Lib/test/test_bytes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import array
8+
import operator
89
import os
910
import re
1011
import sys
@@ -771,6 +772,9 @@ def check(fmt, vals, result):
771772
check(b'%i%b %*.*b', (10, b'3', 5, 3, b'abc',), b'103 abc')
772773
check(b'%c', b'a', b'a')
773774

775+
self.assertRaisesRegex(TypeError, '%i format: a real number is required, not complex', operator.mod, '%i', 2j)
776+
self.assertRaisesRegex(TypeError, '%d format: a real number is required, not complex', operator.mod, '%d', 2j)
777+
774778
def test_imod(self):
775779
b = self.type2test(b'hello, %b!')
776780
orig = b

Lib/test/test_coroutines.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,17 @@ async def g():
11911191
_, result = run_async(g())
11921192
self.assertIsNone(result.__context__)
11931193

1194+
def test_await_17(self):
1195+
# See https://github.com/python/cpython/issues/131666 for details.
1196+
class A:
1197+
async def __anext__(self):
1198+
raise StopAsyncIteration
1199+
def __aiter__(self):
1200+
return self
1201+
1202+
with contextlib.closing(anext(A(), "a").__await__()) as anext_awaitable:
1203+
self.assertRaises(TypeError, anext_awaitable.close, 1)
1204+
11941205
def test_with_1(self):
11951206
class Manager:
11961207
def __init__(self, name):

Lib/test/test_format.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ def test_common_format(self):
283283
"%x format: an integer is required, not str")
284284
test_exc_common('%x', 3.14, TypeError,
285285
"%x format: an integer is required, not float")
286+
test_exc_common('%i', '1', TypeError,
287+
"%i format: a real number is required, not str")
288+
test_exc_common('%i', b'1', TypeError,
289+
"%i format: a real number is required, not bytes")
286290

287291
def test_str_format(self):
288292
testformat("%r", "\u0378", "'\\u0378'") # non printable

0 commit comments

Comments
 (0)