Skip to content

Commit 7083a26

Browse files
committed
[GR-21590] Update imports
PullRequest: graalpython/1705
2 parents 7dbf557 + 034a35c commit 7083a26

File tree

27 files changed

+216
-48
lines changed

27 files changed

+216
-48
lines changed

CHANGELOG.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ language runtime. The main focus is on user-observable behavior of the engine.
77

88
* Support multi-threading with a global interpreter lock by default.
99
* Added SSL/TLS support (the `ssl` module)
10-
11-
## Version 21.1.0
12-
1310
* Added subclassing of Java classes in JVM mode
1411
* Use native posix functions in the GraalPython Launcher
1512
* Support iterating over Python objects from Java and other languages as well as iterating over foreign objects in Python
16-
* Support catching foreign exceptions in catch-all except clauses
17-
18-
## Version 21.1.0
19-
2013
* Support catching exceptions from other languages or Java with catch-all except blocks
21-
* Support iterating over iterables from other languages, as well as allow other languages to iterate over Python iterables and iterators
2214
* Support isinstance and issubclass with instances and classes of other languages
2315

2416
## Version 21.0.0

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "170e550ee492b57eddde3fbe3e2334bcf3ff5d5f" }
1+
{ "overlay": "adca0bf57f88f8e74b181ed5e7e77df445de5bd8" }

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ public class PythonProvider implements LanguageProvider {
8282

8383
private static final String ID = "python";
8484

85-
private static final TypeDescriptor INT = intersection(OBJECT, NUMBER);
86-
// as per interop contract, we cannot be boolean and number at the same time
87-
private static final TypeDescriptor BOOL = intersection(OBJECT, BOOLEAN);
88-
private static final TypeDescriptor FLOAT = intersection(OBJECT, NUMBER);
85+
private static final TypeDescriptor INT = NUMBER;
86+
// as per interop contract, we cannot be boolean and number at the same time, so it's only a
87+
// boolean
88+
private static final TypeDescriptor BOOL = BOOLEAN;
89+
private static final TypeDescriptor FLOAT = NUMBER;
8990
private static final TypeDescriptor COMPLEX = intersection(OBJECT);
90-
private static final TypeDescriptor NONE = intersection(OBJECT, NULL);
91+
private static final TypeDescriptor NONE = NULL;
9192
private static final TypeDescriptor STR = intersection(OBJECT, STRING, ITERABLE, array(STRING));
9293
private static final TypeDescriptor BYTES = intersection(OBJECT, ITERABLE, array(INT));
9394
private static final TypeDescriptor BYTEARRAY = intersection(OBJECT, ITERABLE, array(INT));
@@ -223,15 +224,14 @@ public Collection<? extends Snippet> createExpressions(Context context) {
223224
List<Snippet> snippets = new ArrayList<>();
224225

225226
// @formatter:off
226-
addExpressionSnippet(context, snippets, "+", "lambda x, y: x + y", NUMBER, union(BOOLEAN, NUMBER), union(BOOLEAN, NUMBER));
227-
addExpressionSnippet(context, snippets, "+ str", "lambda x, y: x + y", NUMBER, union(BOOLEAN, NUMBER), union(BOOLEAN, NUMBER));
228-
addExpressionSnippet(context, snippets, "+ list", "lambda x, y: x + y", array(ANY), PNoListCoercionVerifier.INSTANCE, array(ANY), array(ANY));
227+
addExpressionSnippet(context, snippets, "+", "lambda x, y: x + y", union(STRING, NUMBER, array(ANY)), AddVerifier.INSTANCE, union(STRING, BOOLEAN, NUMBER, array(ANY)), union(STRING, BOOLEAN, NUMBER, array(ANY)));
228+
addExpressionSnippet(context, snippets, "*", "lambda x, y: x * y", union(STRING, NUMBER, array(ANY)), MulVerifier.INSTANCE, union(STRING, BOOLEAN, NUMBER, array(ANY)), union(STRING, BOOLEAN, NUMBER, array(ANY)));
229229

230230
addExpressionSnippet(context, snippets, "-", "lambda x, y: x - y", NUMBER, union(BOOLEAN, NUMBER), union(BOOLEAN, NUMBER));
231231

232232
addExpressionSnippet(context, snippets, "/", "lambda x, y: x / y", NUMBER, PDivByZeroVerifier.INSTANCE, union(BOOLEAN, NUMBER), union(BOOLEAN, NUMBER));
233233

234-
addExpressionSnippet(context, snippets, "list-from-foreign", "lambda x: list(x)", array(ANY), union(STRING, iterable(ANY), iterator(ANY), array(ANY)));
234+
// addExpressionSnippet(context, snippets, "list-from-foreign", "lambda x: list(x)", array(ANY), union(STRING, iterable(ANY), iterator(ANY), array(ANY)));
235235

236236
addExpressionSnippet(context, snippets, "==", "lambda x, y: x == y", BOOLEAN, ANY, ANY);
237237
addExpressionSnippet(context, snippets, "!=", "lambda x, y: x != y", BOOLEAN, ANY, ANY);
@@ -266,10 +266,10 @@ public Collection<? extends Snippet> createStatements(Context context) {
266266
" return False\n\n" +
267267
"gen_if", BOOLEAN, ANY);
268268

269-
addStatementSnippet(context, snippets, "for", "def gen_for(l):\n" +
270-
" for x in l:\n" +
271-
" return x\n\n" +
272-
"gen_for", ANY, union(array(ANY), iterable(ANY), iterator(ANY), STRING));
269+
// addStatementSnippet(context, snippets, "for", "def gen_for(l):\n" +
270+
// " for x in l:\n" +
271+
// " return x\n\n" +
272+
// "gen_for", ANY, union(array(ANY), iterable(ANY), iterator(ANY), STRING));
273273

274274
// any exception honours the finally block, but non-exception cannot be raised
275275
addStatementSnippet(context, snippets, "try-finally", "def gen_tryfinally(exc):\n" +
@@ -350,7 +350,7 @@ private abstract static class PResultVerifier implements ResultVerifier {
350350
/**
351351
* Only accepts exact matches of types.
352352
*/
353-
private static class PNoListCoercionVerifier extends PResultVerifier {
353+
private static class AddVerifier extends PResultVerifier {
354354

355355
public void accept(SnippetRun snippetRun) throws PolyglotException {
356356
List<? extends Value> parameters = snippetRun.getParameters();
@@ -363,14 +363,81 @@ public void accept(SnippetRun snippetRun) throws PolyglotException {
363363
// ignore '(1,2) + [3,4]'.
364364
if (par0.hasArrayElements() && par1.hasArrayElements()) {
365365
if (par0.getMetaObject() == par1.getMetaObject()) {
366-
ResultVerifier.getDefaultResultVerifier().accept(snippetRun);
366+
assert snippetRun.getException() == null;
367+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
368+
assert array(ANY).isAssignable(resultType);
367369
}
370+
} else if (par0.isString() && par1.isString()) {
371+
assert snippetRun.getException() == null;
372+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
373+
assert STRING.isAssignable(resultType);
374+
} else if ((par0.isNumber() || par0.isBoolean()) && (par1.isNumber() || par1.isBoolean())) {
375+
assert snippetRun.getException() == null;
376+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
377+
assert NUMBER.isAssignable(resultType);
368378
} else {
369-
ResultVerifier.getDefaultResultVerifier().accept(snippetRun);
379+
assert snippetRun.getException() != null;
380+
TypeDescriptor argType = union(STRING, BOOLEAN, NUMBER, array(ANY));
381+
TypeDescriptor par0Type = TypeDescriptor.forValue(par0);
382+
TypeDescriptor par1Type = TypeDescriptor.forValue(par1);
383+
if (!argType.isAssignable(par0Type) || !argType.isAssignable(par1Type)) {
384+
// argument type error, rethrow
385+
throw snippetRun.getException();
386+
} else {
387+
// arguments are ok, just don't work in this combination
388+
}
389+
}
390+
}
391+
392+
private static final AddVerifier INSTANCE = new AddVerifier();
393+
}
394+
395+
private static class MulVerifier extends PResultVerifier {
396+
397+
private static boolean isStringMul(Value x, Value y) {
398+
return x.isString() && (y.isBoolean() || (y.isNumber() && y.fitsInInt()));
399+
}
400+
401+
private static boolean isArrayMul(Value x, Value y) {
402+
return x.hasArrayElements() && (y.isBoolean() || (y.isNumber() && (y.fitsInInt() || (y.fitsInLong() && y.asLong() < 0))));
403+
}
404+
405+
public void accept(SnippetRun snippetRun) throws PolyglotException {
406+
List<? extends Value> parameters = snippetRun.getParameters();
407+
assert parameters.size() == 2;
408+
409+
Value par0 = parameters.get(0);
410+
Value par1 = parameters.get(1);
411+
412+
if (isStringMul(par0, par1) || isStringMul(par1, par0)) {
413+
// string * number => string
414+
assert snippetRun.getException() == null;
415+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
416+
assert STRING.isAssignable(resultType);
417+
} else if (isArrayMul(par0, par1) || isArrayMul(par1, par0)) {
418+
// array * number => array
419+
assert snippetRun.getException() == null;
420+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
421+
assert array(ANY).isAssignable(resultType);
422+
} else if ((par0.isNumber() || par0.isBoolean()) && (par1.isNumber() || par1.isBoolean())) {
423+
assert snippetRun.getException() == null;
424+
TypeDescriptor resultType = TypeDescriptor.forValue(snippetRun.getResult());
425+
assert NUMBER.isAssignable(resultType);
426+
} else {
427+
assert snippetRun.getException() != null;
428+
TypeDescriptor argType = union(STRING, BOOLEAN, NUMBER, array(ANY));
429+
TypeDescriptor par0Type = TypeDescriptor.forValue(par0);
430+
TypeDescriptor par1Type = TypeDescriptor.forValue(par1);
431+
if (!argType.isAssignable(par0Type) || !argType.isAssignable(par1Type)) {
432+
// argument type error, rethrow
433+
throw snippetRun.getException();
434+
} else {
435+
// arguments are ok, just don't work in this combination
436+
}
370437
}
371438
}
372439

373-
private static final PNoListCoercionVerifier INSTANCE = new PNoListCoercionVerifier();
440+
private static final MulVerifier INSTANCE = new MulVerifier();
374441
}
375442

376443
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,17 +638,17 @@ def test_foreign_slice_setting():
638638
assert True
639639
else:
640640
assert False, "should throw a type error again"
641-
641+
642+
@skipIf(is_native, "not supported in native mode")
642643
def test_foreign_repl():
643644
from java.util.logging import LogRecord
644645
from java.util.logging import Level
645-
646+
646647
lr = LogRecord(Level.ALL, "message")
647648
assert repr(LogRecord).startswith('<JavaClass[java.util.logging.LogRecord] at')
648649
assert repr(lr).startswith('<JavaObject[java.util.logging.LogRecord] at')
649-
650+
650651
from java.lang import Integer
651652
i = Integer('22')
652653
assert repr(Integer).startswith('<JavaClass[java.lang.Integer] at')
653654
assert repr(i) == '22'
654-

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__check_for_unavailable_sdk
22
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__check_for_unavailable_sdk_alternate
3+
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__find_appropriate_compiler
34
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__find_build_tool
45
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__find_executable
56
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__get_system_version
67
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__override_all_archs
8+
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__read_output
79
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__remove_original_values
810
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__remove_universal_flags
911
*graalpython.lib-python.3.test.test__osx_support.Test_OSXSupport.test__remove_universal_flags_alternate

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
@@ -5,6 +5,7 @@
55
*graalpython.lib-python.3.test.test_asyncore.DispatcherTests.test_strerror
66
*graalpython.lib-python.3.test.test_asyncore.DispatcherTests.test_unhandled
77
*graalpython.lib-python.3.test.test_asyncore.FileWrapperTest.test_close_twice
8+
*graalpython.lib-python.3.test.test_asyncore.FileWrapperTest.test_dispatcher
89
*graalpython.lib-python.3.test.test_asyncore.FileWrapperTest.test_recv
910
*graalpython.lib-python.3.test.test_asyncore.FileWrapperTest.test_send
1011
*graalpython.lib-python.3.test.test_asyncore.HelperFunctionTests.test_closeall

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_argv0_normalization
2+
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_builtin_input
23
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_closed_stdout
34
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_del___main__
45
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_directories
@@ -7,6 +8,7 @@
78
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_non_ascii
89
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_output_newline
910
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_run_module_bug1764407
11+
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_stdin_readline
1012
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unbuffered_input
1113
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unbuffered_output
1214
*graalpython.lib-python.3.test.test_cmd_line.CmdLineTest.test_unmached_quote

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
@@ -23,6 +23,7 @@
2323
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue16373
2424
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue26915
2525
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue8750
26+
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue_4920
2627
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue_5647
2728
*graalpython.lib-python.3.test.test_collections.TestCounter.test_basics
2829
*graalpython.lib-python.3.test.test_collections.TestCounter.test_conversions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_close_twice
33
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_create_new
44
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_dumbdbm_creation
5+
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_dumbdbm_creation_mode
56
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_eval
67
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_invalid_flag
78
*graalpython.lib-python.3.test.test_dbm_dumb.DumbDBMTestCase.test_missing_data

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
*graalpython.lib-python.3.test.test_file.PyOtherFileTests.testIteration
2828
*graalpython.lib-python.3.test.test_file.PyOtherFileTests.testModeStrings
2929
*graalpython.lib-python.3.test.test_file.PyOtherFileTests.testSetBufferSize
30+
*graalpython.lib-python.3.test.test_file.PyOtherFileTests.testTruncateOnWindows

0 commit comments

Comments
 (0)