Skip to content

Commit 7fbc725

Browse files
committed
Support for new type parameters syntax in Bytecode DSL interpreter + update Bytecode DSL tags according to 3.12
1 parent bde842f commit 7fbc725

File tree

20 files changed

+1104
-356
lines changed

20 files changed

+1104
-356
lines changed

graalpython/com.oracle.graal.python.pegparser.generator/asdl/asdl_java.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def generate_sst_node(emitter: java_file.Emitter, c: model.ConcreteClass):
108108
if not f.is_nullable and f.type.java not in ('int', 'boolean'):
109109
emitter.println(f'assert {f.name.java} != null;')
110110
emitter.println(f'this.{f.name.java} = {f.name.java};')
111+
if 'typeParams' in [f.name.java for f in c.fields]:
112+
with emitter.define('public boolean isGeneric()'):
113+
emitter.println('return typeParams != null && typeParams.length > 0;')
111114
# accept() method
112115
with emitter.define('public <T> T accept(SSTreeVisitor<T> visitor)', '@Override'):
113116
emitter.println('return visitor.visit(this);')

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/scope/Scope.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ public boolean isFunction() {
227227
return type.isFunctionLike();
228228
}
229229

230+
public boolean isTypeParam() {
231+
return type == ScopeType.TypeParam;
232+
}
233+
230234
public boolean isClass() {
231235
return type == ScopeType.Class;
232236
}

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/sst/StmtTy.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public FunctionDef(String name, ArgumentsTy args, StmtTy[] body, ExprTy[] decora
7575
this.typeParams = typeParams;
7676
}
7777

78+
public boolean isGeneric() {
79+
return typeParams != null && typeParams.length > 0;
80+
}
81+
7882
@Override
7983
public <T> T accept(SSTreeVisitor<T> visitor) {
8084
return visitor.visit(this);
@@ -103,6 +107,10 @@ public AsyncFunctionDef(String name, ArgumentsTy args, StmtTy[] body, ExprTy[] d
103107
this.typeParams = typeParams;
104108
}
105109

110+
public boolean isGeneric() {
111+
return typeParams != null && typeParams.length > 0;
112+
}
113+
106114
@Override
107115
public <T> T accept(SSTreeVisitor<T> visitor) {
108116
return visitor.visit(this);
@@ -128,6 +136,10 @@ public ClassDef(String name, ExprTy[] bases, KeywordTy[] keywords, StmtTy[] body
128136
this.typeParams = typeParams;
129137
}
130138

139+
public boolean isGeneric() {
140+
return typeParams != null && typeParams.length > 0;
141+
}
142+
131143
@Override
132144
public <T> T accept(SSTreeVisitor<T> visitor) {
133145
return visitor.visit(this);
@@ -195,6 +207,10 @@ public TypeAlias(ExprTy name, TypeParamTy[] typeParams, ExprTy value, SourceRang
195207
this.value = value;
196208
}
197209

210+
public boolean isGeneric() {
211+
return typeParams != null && typeParams.length > 0;
212+
}
213+
198214
@Override
199215
public <T> T accept(SSTreeVisitor<T> visitor) {
200216
return visitor.visit(this);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ def get_setuptools(setuptools='setuptools==67.6.1'):
117117
py_executable = temp_env / 'Scripts' / 'python.exe'
118118
else:
119119
py_executable = temp_env / 'bin' / 'python3'
120-
subprocess.run([py_executable, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True)
120+
extra_args = []
121+
if GRAALPYTHON and __graalpython__.is_bytecode_dsl_interpreter:
122+
extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=true']
123+
subprocess.run([py_executable, *extra_args, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True)
121124
print('setuptools is installed in %s' % setuptools_path)
122125
shutil.rmtree(temp_env)
123126

graalpython/com.oracle.graal.python.test/src/tests/test_assign.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -210,3 +210,11 @@ def test_illegal_assignment(self):
210210

211211
with self.assertRaisesRegex(SyntaxError, "assign to list comprehension|invalid syntax\. Maybe you meant '==' or ':=' instead of '='\?"):
212212
compile("[s for s in [1]], b, c = (1, 2, 3)", "<test>", "exec")
213+
214+
215+
class NotIllegaAssigmentTest(unittest.TestCase):
216+
def test_not_syntax_error(self):
217+
# If this changes in CPython, we just need to add the missing forbidden name checks to the bytecode compiler
218+
with self.assertRaises(AttributeError):
219+
x = object()
220+
x.__debug__ += 1

graalpython/com.oracle.graal.python.test/src/tests/test_decorators.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -58,3 +58,54 @@ def myfunc(a, b, **kwargs):
5858
assert global_log[-1] == ["myfunc", (10, 20), {}]
5959
assert myfunc(10, 20, x=1, y=2) == (10, 20, {'x': 1, 'y': 2})
6060
assert global_log[-1] == ["myfunc", (10, 20), {'x': 1, 'y': 2}]
61+
62+
63+
def test_eval_order():
64+
MyBase = None
65+
66+
def create_base(dummy_arg):
67+
nonlocal MyBase
68+
class MyBaseK:
69+
pass
70+
MyBase = MyBaseK
71+
return lambda a: a
72+
73+
# this should just work: the decorator expression first
74+
# creates MyBase and only then is the rest evaluated
75+
@create_base('dummy')
76+
class MyClass(MyBase):
77+
pass
78+
79+
# dummy helper for following tests
80+
def my_decorator(x):
81+
return x
82+
83+
class assert_name_error:
84+
def __init__(self, name):
85+
self.name = name
86+
def __enter__(self):
87+
pass
88+
def __exit__(self, exc_type, exc_val, exc_tb):
89+
assert exc_type == NameError, f"did not raise NameError with name '{self.name}'"
90+
assert self.name in str(exc_val), f"not NameError for name '{self.name}'"
91+
return True
92+
93+
with assert_name_error('my_decoratorr'):
94+
@my_decoratorr
95+
class ClassA(NonExistingBaseClass):
96+
pass
97+
98+
with assert_name_error('NonExistingBase'):
99+
@my_decorator
100+
class ClassA(NonExistingBase):
101+
pass
102+
103+
with assert_name_error('my_decoratorr'):
104+
@my_decoratorr
105+
def my_function(x=NonexistingName):
106+
pass
107+
108+
with assert_name_error('NonexistingDefaultName'):
109+
@my_decorator
110+
def my_function(x=NonexistingDefaultName):
111+
pass

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_eof.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ test.test_eof.EOFTestCase.test_EOFS @ linux-x86_64
22
test.test_eof.EOFTestCase.test_EOFS_with_file @ linux-x86_64
33
test.test_eof.EOFTestCase.test_EOF_single_quote @ linux-x86_64
44
test.test_eof.EOFTestCase.test_eof_with_line_continuation @ linux-x86_64
5-
test.test_eof.EOFTestCase.test_line_continuation_EOF @ linux-x86_64
6-
test.test_eof.EOFTestCase.test_line_continuation_EOF_from_file_bpo2180 @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_fstring.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ test.test_fstring.TestCase.test_arguments @ linux-x86_64
33
test.test_fstring.TestCase.test_assignment @ linux-x86_64
44
test.test_fstring.TestCase.test_ast @ linux-x86_64
55
test.test_fstring.TestCase.test_ast_compile_time_concat @ linux-x86_64
6+
test.test_fstring.TestCase.test_ast_fstring_empty_format_spec @ linux-x86_64
67
test.test_fstring.TestCase.test_ast_line_numbers @ linux-x86_64
78
test.test_fstring.TestCase.test_ast_line_numbers_duplicate_expression @ linux-x86_64
9+
test.test_fstring.TestCase.test_ast_line_numbers_multiline_fstring @ linux-x86_64
810
test.test_fstring.TestCase.test_ast_line_numbers_multiple_formattedvalues @ linux-x86_64
911
test.test_fstring.TestCase.test_ast_line_numbers_nested @ linux-x86_64
12+
test.test_fstring.TestCase.test_ast_line_numbers_with_parentheses @ linux-x86_64
1013
test.test_fstring.TestCase.test_ast_numbers_fstring_with_formatting @ linux-x86_64
1114
test.test_fstring.TestCase.test_backslash_char @ linux-x86_64
15+
test.test_fstring.TestCase.test_backslashes_in_expression_part @ linux-x86_64
1216
test.test_fstring.TestCase.test_backslashes_in_string_part @ linux-x86_64
1317
test.test_fstring.TestCase.test_call @ linux-x86_64
1418
test.test_fstring.TestCase.test_closure @ linux-x86_64
1519
test.test_fstring.TestCase.test_comments @ linux-x86_64
1620
test.test_fstring.TestCase.test_compile_time_concat @ linux-x86_64
1721
test.test_fstring.TestCase.test_compile_time_concat_errors @ linux-x86_64
1822
test.test_fstring.TestCase.test_conversions @ linux-x86_64
23+
test.test_fstring.TestCase.test_custom_format_specifier @ linux-x86_64
1924
test.test_fstring.TestCase.test_debug_conversion @ linux-x86_64
25+
test.test_fstring.TestCase.test_debug_in_file @ linux-x86_64
2026
test.test_fstring.TestCase.test_del @ linux-x86_64
2127
test.test_fstring.TestCase.test_dict @ linux-x86_64
2228
test.test_fstring.TestCase.test_docstring @ linux-x86_64
@@ -27,8 +33,14 @@ test.test_fstring.TestCase.test_errors @ linux-x86_64
2733
test.test_fstring.TestCase.test_expressions_with_triple_quoted_strings @ linux-x86_64
2834
test.test_fstring.TestCase.test_filename_in_syntaxerror @ linux-x86_64
2935
test.test_fstring.TestCase.test_format_specifier_expressions @ linux-x86_64
36+
test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket @ linux-x86_64
37+
test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket_warns_once @ linux-x86_64
38+
test.test_fstring.TestCase.test_fstring_backslash_prefix_raw @ linux-x86_64
39+
test.test_fstring.TestCase.test_fstring_format_spec_greedy_matching @ linux-x86_64
40+
test.test_fstring.TestCase.test_fstring_nested_too_deeply @ linux-x86_64
3041
test.test_fstring.TestCase.test_global @ linux-x86_64
3142
test.test_fstring.TestCase.test_if_conditional @ linux-x86_64
43+
test.test_fstring.TestCase.test_invalid_backslashes_inside_fstring_context @ linux-x86_64
3244
test.test_fstring.TestCase.test_invalid_string_prefixes @ linux-x86_64
3345
test.test_fstring.TestCase.test_invalid_syntax_error_message @ linux-x86_64
3446
test.test_fstring.TestCase.test_lambda @ linux-x86_64
@@ -52,11 +64,15 @@ test.test_fstring.TestCase.test_no_backslashes_in_expression_part @ linux-x86_64
5264
test.test_fstring.TestCase.test_no_escapes_for_braces @ linux-x86_64
5365
test.test_fstring.TestCase.test_not_equal @ linux-x86_64
5466
test.test_fstring.TestCase.test_parens_in_expressions @ linux-x86_64
67+
test.test_fstring.TestCase.test_roundtrip_raw_quotes @ linux-x86_64
5568
test.test_fstring.TestCase.test_shadowed_global @ linux-x86_64
5669
test.test_fstring.TestCase.test_side_effect_order @ linux-x86_64
5770
test.test_fstring.TestCase.test_str_format_differences @ linux-x86_64
71+
test.test_fstring.TestCase.test_syntax_error_after_debug @ linux-x86_64
5872
test.test_fstring.TestCase.test_syntax_error_for_starred_expressions @ linux-x86_64
73+
test.test_fstring.TestCase.test_syntax_error_in_nested_fstring @ linux-x86_64
5974
test.test_fstring.TestCase.test_unterminated_string @ linux-x86_64
75+
test.test_fstring.TestCase.test_valid_prefixes @ linux-x86_64
6076
test.test_fstring.TestCase.test_walrus @ linux-x86_64
6177
test.test_fstring.TestCase.test_with_a_commas_and_an_underscore_in_format_specifier @ linux-x86_64
6278
test.test_fstring.TestCase.test_with_an_underscore_and_a_comma_in_format_specifier @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_hashlib.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,3 @@ test.test_hashlib.HashLibTestCase.test_usedforsecurity_false @ linux-x86_64
5959
test.test_hashlib.HashLibTestCase.test_usedforsecurity_true @ linux-x86_64
6060
test.test_hashlib.KDFTests.test_file_digest @ linux-x86_64
6161
test.test_hashlib.KDFTests.test_normalized_name @ linux-x86_64
62-
test.test_hashlib.KDFTests.test_pbkdf2_hmac_c @ linux-x86_64
63-
test.test_hashlib.KDFTests.test_pbkdf2_hmac_py @ linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags_bytecode_dsl/test_imp.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)