Skip to content

Commit 902af47

Browse files
committed
Fix up
1 parent a679442 commit 902af47

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

Lib/test/test_type_params.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import annotations
1+
import annotationlib
22
import asyncio
33
import textwrap
44
import types
@@ -1421,9 +1421,9 @@ def f[T: int = int, **P = int, *Ts = int](): pass
14211421
for case in cases:
14221422
with self.subTest(case=case):
14231423
self.assertIs(case(1), int)
1424-
self.assertIs(annotations.call_evaluate_function(case, annotations.Format.VALUE), int)
1425-
self.assertIs(annotations.call_evaluate_function(case, annotations.Format.FORWARDREF), int)
1426-
self.assertEqual(annotations.call_evaluate_function(case, annotations.Format.SOURCE), 'int')
1424+
self.assertIs(annotationlib.call_evaluate_function(case, annotationlib.Format.VALUE), int)
1425+
self.assertIs(annotationlib.call_evaluate_function(case, annotationlib.Format.FORWARDREF), int)
1426+
self.assertEqual(annotationlib.call_evaluate_function(case, annotationlib.Format.SOURCE), 'int')
14271427

14281428
def test_constraints(self):
14291429
def f[T: (int, str)](): pass
@@ -1432,6 +1432,6 @@ def f[T: (int, str)](): pass
14321432
for case in [T, T2]:
14331433
with self.subTest(case=case):
14341434
self.assertEqual(case.evaluate_constraints(1), (int, str))
1435-
self.assertEqual(annotations.call_evaluate_function(case.evaluate_constraints, annotations.Format.VALUE), (int, str))
1436-
self.assertEqual(annotations.call_evaluate_function(case.evaluate_constraints, annotations.Format.FORWARDREF), (int, str))
1437-
self.assertEqual(annotations.call_evaluate_function(case.evaluate_constraints, annotations.Format.SOURCE), '(int, str)')
1435+
self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.VALUE), (int, str))
1436+
self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.FORWARDREF), (int, str))
1437+
self.assertEqual(annotationlib.call_evaluate_function(case.evaluate_constraints, annotationlib.Format.SOURCE), '(int, str)')

Python/compile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,7 @@ compiler_type_param_bound_or_default(struct compiler *c, expr_ty e,
20392039
{
20402040
PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne());
20412041
ADDOP_LOAD_CONST_NEW(c, LOC(e), defaults);
2042-
if (compiler_enter_scope(c, name, COMPILER_SCOPE_ANNOTATIONS,
2043-
key, e->lineno, NULL) == -1) {
2042+
if (compiler_setup_annotations_scope(c, LOC(e), key, name) == -1) {
20442043
return ERROR;
20452044
}
20462045
if (allow_starred && e->kind == Starred_kind) {
@@ -2631,7 +2630,7 @@ compiler_typealias_body(struct compiler *c, stmt_ty s)
26312630
PyObject *defaults = PyTuple_Pack(1, _PyLong_GetOne());
26322631
ADDOP_LOAD_CONST_NEW(c, loc, defaults);
26332632
RETURN_IF_ERROR(
2634-
compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION, s, loc.lineno, NULL));
2633+
compiler_setup_annotations_scope(c, LOC(s), s, name));
26352634
/* Make None the first constant, so the evaluate function can't have a
26362635
docstring. */
26372636
RETURN_IF_ERROR(compiler_add_const(c, Py_None));

Python/symtable.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ static int symtable_visit_pattern(struct symtable *st, pattern_ty s);
260260
static int symtable_raise_if_annotation_block(struct symtable *st, const char *, expr_ty);
261261
static int symtable_raise_if_not_coroutine(struct symtable *st, const char *msg, _Py_SourceLocation loc);
262262
static int symtable_raise_if_comprehension_block(struct symtable *st, expr_ty);
263-
static int symtable_add_def(struct symtable *st, PyObject *name, int flag,
264-
int lineno, int col_offset, int end_lineno, int end_col_offset);
263+
static int symtable_add_def(struct symtable *st, PyObject *name, int flag, _Py_SourceLocation loc);
265264

266265
/* For debugging purposes only */
267266
#if _PY_DUMP_SYMTABLE
@@ -1390,15 +1389,13 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
13901389
return 0;
13911390
int result = symtable_enter_existing_block(st, ste);
13921391
Py_DECREF(ste);
1393-
if (block == AnnotationBlock || block == TypeVarBoundBlock || block == TypeAliasBlock) {
1392+
if (block == AnnotationBlock || block == TypeVariableBlock || block == TypeAliasBlock) {
13941393
_Py_DECLARE_STR(format, ".format");
13951394
// We need to insert code that reads this "parameter" to the function.
1396-
if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM,
1397-
lineno, col_offset, end_lineno, end_col_offset)) {
1395+
if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM, loc)) {
13981396
return 0;
13991397
}
1400-
if (!symtable_add_def(st, &_Py_STR(format), USE,
1401-
lineno, col_offset, end_lineno, end_col_offset)) {
1398+
if (!symtable_add_def(st, &_Py_STR(format), USE, loc)) {
14021399
return 0;
14031400
}
14041401
}

0 commit comments

Comments
 (0)