Skip to content

Commit 53d0f41

Browse files
CPython Developersyouknowone
authored andcommitted
Update from CPython v3.10.9
1 parent a0c34da commit 53d0f41

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Lib/ast.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ def parse(source, filename='<unknown>', mode='exec', *,
5353

5454
def literal_eval(node_or_string):
5555
"""
56-
Safely evaluate an expression node or a string containing a Python
56+
Evaluate an expression node or a string containing only a Python
5757
expression. The string or node provided may only consist of the following
5858
Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
5959
sets, booleans, and None.
60+
61+
Caution: A complex expression can overflow the C stack and cause a crash.
6062
"""
6163
if isinstance(node_or_string, str):
6264
node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
@@ -234,6 +236,12 @@ def increment_lineno(node, n=1):
234236
location in a file.
235237
"""
236238
for child in walk(node):
239+
# TypeIgnore is a special case where lineno is not an attribute
240+
# but rather a field of the node itself.
241+
if isinstance(child, TypeIgnore):
242+
child.lineno = getattr(child, 'lineno', 0) + n
243+
continue
244+
237245
if 'lineno' in child._attributes:
238246
child.lineno = getattr(child, 'lineno', 0) + n
239247
if (
@@ -849,7 +857,7 @@ def visit_Import(self, node):
849857

850858
def visit_ImportFrom(self, node):
851859
self.fill("from ")
852-
self.write("." * node.level)
860+
self.write("." * (node.level or 0))
853861
if node.module:
854862
self.write(node.module)
855863
self.write(" import ")

Lib/dataclasses.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,11 @@ def wrapper(self):
411411

412412
def _create_fn(name, args, body, *, globals=None, locals=None,
413413
return_type=MISSING):
414-
# Note that we mutate locals when exec() is called. Caller
415-
# beware! The only callers are internal to this module, so no
414+
# Note that we may mutate locals. Callers beware!
415+
# The only callers are internal to this module, so no
416416
# worries about external callers.
417417
if locals is None:
418418
locals = {}
419-
if 'BUILTINS' not in locals:
420-
locals['BUILTINS'] = builtins
421419
return_annotation = ''
422420
if return_type is not MISSING:
423421
locals['_return_type'] = return_type
@@ -443,7 +441,7 @@ def _field_assign(frozen, name, value, self_name):
443441
# self_name is what "self" is called in this function: don't
444442
# hard-code "self", since that might be a field name.
445443
if frozen:
446-
return f'BUILTINS.object.__setattr__({self_name},{name!r},{value})'
444+
return f'__dataclass_builtins_object__.__setattr__({self_name},{name!r},{value})'
447445
return f'{self_name}.{name}={value}'
448446

449447

@@ -550,6 +548,7 @@ def _init_fn(fields, std_fields, kw_only_fields, frozen, has_post_init,
550548
locals.update({
551549
'MISSING': MISSING,
552550
'_HAS_DEFAULT_FACTORY': _HAS_DEFAULT_FACTORY,
551+
'__dataclass_builtins_object__': object,
553552
})
554553

555554
body_lines = []

0 commit comments

Comments
 (0)