Skip to content

Commit c0124e7

Browse files
committed
Merge branch 'master' into feature/GR-20901
# Conflicts: # graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
2 parents 3ece43c + c42d934 commit c0124e7

File tree

201 files changed

+3408
-1973
lines changed

Some content is hidden

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

201 files changed

+3408
-1973
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "9f88a237b49801c25c4633e22d9a95c38032f9f2" }
1+
{ "overlay": "342d54c7c779683771fd346ae919235334523e58" }

graalpython/com.oracle.graal.python.benchmarks/python/micro/try-except-sized.py

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

graalpython/com.oracle.graal.python.benchmarks/python/micro/try-except-store-sized.py

Lines changed: 0 additions & 66 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.test.objects;
42+
43+
import com.oracle.graal.python.builtins.objects.PNone;
44+
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
45+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
46+
47+
import com.oracle.graal.python.test.PythonTests;
48+
import java.util.concurrent.Callable;
49+
50+
import org.graalvm.polyglot.Context;
51+
import org.graalvm.polyglot.Value;
52+
import org.graalvm.polyglot.proxy.ProxyExecutable;
53+
import org.junit.After;
54+
import static org.junit.Assert.assertNotNull;
55+
import static org.junit.Assert.assertNotSame;
56+
import static org.junit.Assert.assertSame;
57+
import static org.junit.Assert.fail;
58+
import org.junit.Before;
59+
import org.junit.Test;
60+
61+
public class PythonObjectLibraryTests extends PythonTests {
62+
63+
private Context context;
64+
65+
@Before
66+
public void setUpTest() {
67+
Context.Builder builder = Context.newBuilder();
68+
builder.allowExperimentalOptions(true);
69+
builder.allowAllAccess(true);
70+
context = builder.build();
71+
}
72+
73+
@After
74+
public void tearDown() {
75+
context.close();
76+
}
77+
78+
@Test
79+
public void testLookupAttribute() {
80+
lookupAttr(() -> true, "__str__", false);
81+
lookupAttr(() -> 1.1, "__str__", false);
82+
lookupAttr(() -> 1, "__str__", false);
83+
lookupAttr(() -> (long) 1, "__str__", false);
84+
lookupAttr(() -> "abc", "__str__", false);
85+
86+
lookupAttr(() -> new Object(), "__str__", true);
87+
88+
lookupAttr(() -> PythonObjectFactory.getUncached().createInt(1), "__str__", false);
89+
90+
String noSuchMethod = "__nnoossuuttschmeethod__";
91+
lookupAttr(() -> true, noSuchMethod, true);
92+
lookupAttr(() -> 1.1, noSuchMethod, true);
93+
lookupAttr(() -> 1, noSuchMethod, true);
94+
lookupAttr(() -> (long) 1, "__strt__", true);
95+
lookupAttr(() -> "abc", noSuchMethod, true);
96+
}
97+
98+
private void lookupAttr(Callable<Object> createValue, String attrName, boolean expectNoValue) {
99+
PythonObjectLibrary lib = PythonObjectLibrary.getFactory().getUncached();
100+
execInContext(() -> {
101+
Object value = createValue.call();
102+
Object attr = lib.lookupAttribute(value, attrName, false);
103+
assertAttr(attr, expectNoValue);
104+
105+
attr = lib.lookupAttribute(value, attrName, true);
106+
assertAttr(attr, expectNoValue);
107+
return null;
108+
});
109+
}
110+
111+
private static void assertAttr(Object attr, boolean expectNoValue) {
112+
assertNotNull(attr);
113+
if (expectNoValue) {
114+
assertSame(PNone.NO_VALUE, attr);
115+
} else {
116+
assertNotSame(PNone.NO_VALUE, attr);
117+
}
118+
}
119+
120+
public void execInContext(Callable<Object> c) {
121+
context.initialize("python");
122+
context.getPolyglotBindings().putMember("testSymbol", (ProxyExecutable) (Value... args) -> {
123+
try {
124+
return c.call();
125+
} catch (Exception ex) {
126+
ex.printStackTrace();
127+
fail();
128+
}
129+
return null;
130+
});
131+
context.getPolyglotBindings().getMember("testSymbol").execute();
132+
}
133+
134+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939

40+
import unittest
4041

4142
def assert_raises(err, fn, *args, **kwargs):
4243
raised = False
@@ -117,3 +118,30 @@ def __init__(self):
117118
id(a) # id is stored in a HiddenKey
118119

119120
return
121+
122+
class IllegaAssigmentTest(unittest.TestCase):
123+
def test_illegal_assignment(self):
124+
with self.assertRaisesRegex(SyntaxError, "assign to function call"):
125+
compile("a() = 1", "<test>", "exec")
126+
127+
with self.assertRaisesRegex(SyntaxError, "assign to function call"):
128+
compile("a() += 1", "<test>", "exec")
129+
130+
with self.assertRaisesRegex(SyntaxError, "assign to function call"):
131+
str = "def set() :\n\tprint(42)\n\nset() = 5"
132+
compile(str, "<test>", "exec")
133+
134+
with self.assertRaisesRegex(SyntaxError, "assign to function call"):
135+
compile("a(), b, c = (1, 2, 3)", "<test>", "exec")
136+
137+
with self.assertRaisesRegex(SyntaxError, "assign to function call"):
138+
compile("a, b(), c = (1, 2, 3)", "<test>", "exec")
139+
140+
with self.assertRaisesRegex(SyntaxError, "assign to dict comprehension"):
141+
compile("{s:s for s in [1]}, b, c = (1, 2, 3)", "<test>", "exec")
142+
143+
with self.assertRaisesRegex(SyntaxError, "assign to set comprehension"):
144+
compile("{s for s in [1]}, b, c = (1, 2, 3)", "<test>", "exec")
145+
146+
with self.assertRaisesRegex(SyntaxError, "assign to list comprehension"):
147+
compile("[s for s in [1]], b, c = (1, 2, 3)", "<test>", "exec")

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_asyncore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
*DispatcherTests.test_unhandled
77
*HelperFunctionTests.test_closeall
88
*HelperFunctionTests.test_closeall_default
9+
*HelperFunctionTests.test_compact_traceback
910
*HelperFunctionTests.test_readwrite
1011
*HelperFunctionTests.test_readwriteexc
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*AugAssignTest.testBasic
2+
*AugAssignTest.testCustomMethods1
3+
*AugAssignTest.testCustomMethods2
4+
*AugAssignTest.testInDict
5+
*AugAssignTest.testInList
6+
*AugAssignTest.testSequences
7+
*AugAssignTest.test_with_unpacking

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_collections.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*TestCollectionABCs.test_ByteString
99
*TestCollectionABCs.test_MutableMapping_subclass
1010
*TestCollectionABCs.test_MutableSequence_mixins
11+
*TestCollectionABCs.test_Sequence_mixins
1112
*TestCollectionABCs.test_arithmetic_Set
1213
*TestCollectionABCs.test_equality_Set
1314
*TestCollectionABCs.test_hash_Set

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_configparser.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
*CoverageOneHundredTestCase.test_readfp_deprecation
3131
*CoverageOneHundredTestCase.test_safeconfigparser_deprecation
3232
*CoverageOneHundredTestCase.test_sectionproxy_repr
33+
*ExceptionContextTestCase.test_get_basic_interpolation
34+
*ExceptionContextTestCase.test_get_extended_interpolation
35+
*ExceptionContextTestCase.test_missing_options
36+
*ExceptionContextTestCase.test_missing_section
37+
*ExceptionContextTestCase.test_remove_option
3338
*InlineCommentStrippingTestCase.test_stripping
3439
*Issue7005TestCase.test_none_as_value_stringified
3540
*Issue7005TestCase.test_none_as_value_stringified_raw

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_contextlib.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*ContextManagerTestCase.test_contextmanager_except
88
*ContextManagerTestCase.test_contextmanager_except_stopiter
99
*ContextManagerTestCase.test_contextmanager_finally
10+
*ContextManagerTestCase.test_contextmanager_no_reraise
1011
*ContextManagerTestCase.test_contextmanager_plain
1112
*ContextManagerTestCase.test_contextmanager_trap_yield_after_throw
1213
*ContextManagerTestCase.test_instance_docstring_given_cm_docstring
@@ -31,3 +32,12 @@
3132
*TestContextDecorator.test_instance_docs
3233
*TestContextDecorator.test_typo_enter
3334
*TestContextDecorator.test_typo_exit
35+
*TestSuppress.test_cm_is_reentrant
36+
*TestSuppress.test_exact_exception
37+
*TestSuppress.test_exception_hierarchy
38+
*TestSuppress.test_instance_docs
39+
*TestSuppress.test_multiple_exception_args
40+
*TestSuppress.test_no_args
41+
*TestSuppress.test_no_exception
42+
*TestSuppress.test_no_result_from_enter
43+
*TestSuppress.test_other_exception

0 commit comments

Comments
 (0)