Skip to content

Commit 7ab8cff

Browse files
committed
Merge branch 'master' into bugfix/GR-14380
2 parents 0b2f7d6 + 1c71d93 commit 7ab8cff

File tree

26 files changed

+2543
-2456
lines changed

26 files changed

+2543
-2456
lines changed

3rd_party_licenses.txt

Lines changed: 1964 additions & 2356 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Component
44
This is a release of GraalVM Community Edition 1.0 Python Language Component.
55
This particular copy of the software is released under Universal Permissive
66
License (UPL) v. 1.0.
7-
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved
7+
Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved
88

99
===========================================================================
1010
Universal Permissive License v. 1.0.

ci.jsonnet

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@
244244
name: "deploy-binaries-"+platform,
245245
},
246246

247+
local coverageGate = commonBuilder + {
248+
targets: TARGET.weekly,
249+
run +: [
250+
// cannot run with excluded "GeneratedBy" since that would lead to "command line too long"
251+
// ['mx', '--jacoco-whitelist-package', 'com.oracle.graal.python', '--jacoco-exclude-annotation', '@GeneratedBy', '--strict-compliance', "--dynamicimports", super.dynamicImports, "--primary", 'gate', '-B=--force-deprecation-as-warning-for-dependencies', '--strict-mode', '--tags', "python-junit", '--jacocout', 'html'],
252+
// ['mx', '--jacoco-whitelist-package', 'com.oracle.graal.python', '--jacoco-exclude-annotation', '@GeneratedBy', 'sonarqube-upload', "-Dsonar.host.url=$SONAR_HOST_URL", "-Dsonar.projectKey=com.oracle.graalvm.python", "-Dsonar.projectName=GraalVM - Python", '--exclude-generated'],
253+
['mx', '--jacoco-whitelist-package', 'com.oracle.graal.python', '--strict-compliance', "--dynamicimports", super.dynamicImports, "--primary", 'gate', '-B=--force-deprecation-as-warning-for-dependencies', '--strict-mode', '--tags', "python-junit", '--jacocout', 'html'],
254+
['mx', '--jacoco-whitelist-package', 'com.oracle.graal.python', 'sonarqube-upload', "-Dsonar.host.url=$SONAR_HOST_URL", "-Dsonar.projectKey=com.oracle.graalvm.python", "-Dsonar.projectName=GraalVM - Python", '--exclude-generated'],
255+
],
256+
name: "python-coverage"
257+
} + getPlatform(platform="linux"),
247258
// ------------------------------------------------------------------------------------------------------
248259
//
249260
// the gates
@@ -263,6 +274,9 @@
263274
// style
264275
styleGate,
265276

277+
// coverage
278+
coverageGate,
279+
266280
// graalvm gates
267281
graalVmGate,
268282

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def test_boolean2int():
6767
assert int(False) == 0
6868

6969

70+
def test_bigint_mul():
71+
assert 99999937497465632974931 * 1223432423545234234123123 == 122343165886896325043539375228725106116626429513
72+
assert 99999937497465632974931 * (2**100) == 126764980791447734004805377032945185921379990352429056
73+
74+
7075
def test_int_from_custom():
7176
class CustomInt4():
7277
def __int__(self):

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, 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
@@ -70,3 +70,22 @@ def test_call_builtin_method():
7070
def test_call_builtin_unbound_method():
7171
x = {1: 2}
7272
assert dict.__getitem__.__call__(x, 1) == 2
73+
74+
75+
def test_make_method():
76+
method_type = type(X().foo)
77+
78+
class A():
79+
def __init__(self, *args):
80+
pass
81+
82+
def __call__(self, x, y):
83+
assert isinstance(x, str)
84+
assert isinstance(self, A)
85+
return "A" + str(x) + str(y)
86+
87+
method1 = method_type(A, A)
88+
method2 = method_type(A(), " is ")
89+
90+
assert isinstance(method1(), A)
91+
assert method2(1) == "A is 1", method2(1)

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, value):
1313
def __index__(self):
1414
return self.value
1515

16+
1617
def test_find():
1718
assert "teststring".find("test") == 0
1819
assert "teststring".find("string") == 4
@@ -80,6 +81,7 @@ def test_rfind():
8081
assert s.rfind('ahoj', 16, 20) == 16
8182
assert s.rfind('ahoj', 16, 19) == -1
8283

84+
8385
def test_format():
8486
assert "{}.{}".format("part1", "part2") == "part1.part2"
8587
assert "{0}.{1}".format("part1", "part2") == "part1.part2"
@@ -1023,34 +1025,74 @@ def test_translate():
10231025
else:
10241026
assert False, "should raise"
10251027

1028+
10261029
def test_translate_from_byte_table():
10271030
table = bytes.maketrans(bytes(string.ascii_lowercase, 'ascii'), bytes(string.ascii_uppercase, 'ascii'))
10281031
assert "ahoj".translate(table) == "AHOJ"
10291032
assert "ahoj".translate(bytearray(table)) == "AHOJ"
10301033
assert "ahoj".translate(memoryview(table)) == "AHOJ"
10311034

1035+
10321036
def test_tranlslate_from_short_table():
10331037
table = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGH'
10341038
assert "ahoj".translate(table) == "AHoj"
10351039

1040+
10361041
def test_translate_nonascii_from_byte_table():
10371042
table = bytes.maketrans(bytes(string.ascii_lowercase, 'ascii'), bytes(string.ascii_uppercase, 'ascii'))
10381043
assert "ačhřožj".translate(table) == "AčHřOžJ"
10391044

1045+
10401046
def test_translate_from_long_byte_table():
10411047
table = bytes.maketrans(bytes(string.ascii_lowercase, 'ascii'), bytes(string.ascii_uppercase, 'ascii'))
10421048
table *= 30
10431049
assert 'ahoj453875287ščřžýáí'.translate(table) == 'AHOJ453875287A\rY~ýáí'
10441050

1051+
10451052
def test_splitlines():
10461053
assert len(str.splitlines("\n\n")) == 2
10471054
assert len(str.splitlines("\n")) == 1
10481055
assert len(str.splitlines("a\nb")) == 2
10491056

1057+
10501058
def test_literals():
10511059
s = "hello\[world\]"
10521060
assert len(s) == 14
10531061
assert "hello\[world\]"[5] == "\\"
10541062
assert "hello\[world\]"[6] == "["
10551063
assert "hello\[world\]"[12] == "\\"
10561064
assert "hello\[world\]"[13] == "]"
1065+
1066+
1067+
def test_strip_whitespace():
1068+
assert 'hello' == ' hello '.strip()
1069+
assert 'hello ' == ' hello '.lstrip()
1070+
assert ' hello' == ' hello '.rstrip()
1071+
assert 'hello' == 'hello'.strip()
1072+
1073+
b = ' \t\n\r\f\vabc \t\n\r\f\v'
1074+
assert 'abc' == b.strip()
1075+
assert 'abc \t\n\r\f\v' == b.lstrip()
1076+
assert ' \t\n\r\f\vabc' == b.rstrip()
1077+
1078+
# strip/lstrip/rstrip with None arg
1079+
assert 'hello' == ' hello '.strip(None)
1080+
assert 'hello ' == ' hello '.lstrip(None)
1081+
assert ' hello' == ' hello '.rstrip(None)
1082+
assert 'hello' == 'hello'.strip(None)
1083+
1084+
1085+
def test_strip_with_sep():
1086+
# strip/lstrip/rstrip with str arg
1087+
assert 'hello' == 'xyzzyhelloxyzzy'.strip('xyz')
1088+
assert 'helloxyzzy' == 'xyzzyhelloxyzzy'.lstrip('xyz')
1089+
assert 'xyzzyhello' == 'xyzzyhelloxyzzy'.rstrip('xyz')
1090+
assert 'hello' == 'hello'.strip('xyz')
1091+
assert '' == 'mississippi'.strip('mississippi')
1092+
1093+
# only trim the start and end; does not strip internal characters
1094+
assert 'mississipp' == 'mississippi'.strip('i')
1095+
1096+
assertRaises(TypeError, 'hello', 'strip', 42, 42)
1097+
assertRaises(TypeError, 'hello', 'lstrip', 42, 42)
1098+
assertRaises(TypeError, 'hello', 'rstrip', 42, 42)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
141141
import com.oracle.graal.python.nodes.control.GetIteratorNode;
142142
import com.oracle.graal.python.nodes.control.GetNextNode;
143+
import com.oracle.graal.python.nodes.datamodel.IsCallableNode;
143144
import com.oracle.graal.python.nodes.datamodel.IsIndexNode;
144145
import com.oracle.graal.python.nodes.datamodel.IsSequenceNode;
145146
import com.oracle.graal.python.nodes.expression.CastToListNode;
@@ -2378,13 +2379,23 @@ public Object generator(Object args, Object kwargs) {
23782379
@GenerateNodeFactory
23792380
public abstract static class MethodTypeNode extends PythonTernaryBuiltinNode {
23802381
@Specialization
2381-
Object method(LazyPythonClass cls, Object self, PFunction func) {
2382+
Object method(LazyPythonClass cls, PFunction func, Object self) {
23822383
return factory().createMethod(cls, self, func);
23832384
}
23842385

2385-
@Specialization(guards = "isPythonBuiltinClass(cls)")
2386-
Object methodGeneric(@SuppressWarnings("unused") LazyPythonClass cls, Object self, PBuiltinFunction func) {
2387-
return factory().createBuiltinMethod(self, func);
2386+
@Specialization
2387+
Object methodBuiltin(@SuppressWarnings("unused") LazyPythonClass cls, PBuiltinFunction func, Object self) {
2388+
return factory().createMethod(self, func);
2389+
}
2390+
2391+
@Specialization
2392+
Object methodGeneric(@SuppressWarnings("unused") LazyPythonClass cls, Object func, Object self,
2393+
@Cached("create()") IsCallableNode isCallable) {
2394+
if (isCallable.execute(func)) {
2395+
return factory().createMethod(self, func);
2396+
} else {
2397+
throw raise(TypeError, "first argument must be callable");
2398+
}
23882399
}
23892400
}
23902401

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/ManagedMethodWrappersMR.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.oracle.truffle.api.interop.Resolve;
6161
import com.oracle.truffle.api.nodes.ExplodeLoop;
6262
import com.oracle.truffle.api.nodes.Node;
63-
import com.oracle.truffle.api.profiles.PrimitiveValueProfile;
6463

6564
@MessageResolution(receiverType = MethodWrapper.class)
6665
public class ManagedMethodWrappersMR {
@@ -76,8 +75,6 @@ abstract static class ExecuteNode extends Node {
7675
@Child private ExecuteKeywordStarargsNode expandKwargsNode = ExecuteKeywordStarargsNode.create();
7776
@Child private CallNode dispatch;
7877

79-
private final PrimitiveValueProfile starArgsLenProfile = PrimitiveValueProfile.createEqualityProfile();
80-
8178
public Object access(MethKeywords object, Object[] arguments) {
8279
if (arguments.length != 3) {
8380
throw ArityException.raise(3, arguments.length);
@@ -90,8 +87,7 @@ public Object access(MethKeywords object, Object[] arguments) {
9087
Object kwArgs = toJavaNode.execute(arguments[2]);
9188

9289
Object[] starArgsArray = posStarargsNode.executeWith(starArgs);
93-
int starArgsLen = starArgsLenProfile.profile(starArgsArray.length);
94-
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray, starArgsLen);
90+
Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray);
9591
PKeyword[] kwArgsArray = expandKwargsNode.executeWith(kwArgs);
9692

9793
// execute

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ public abstract static class GetCodeNode extends PythonBuiltinNode {
162162
protected Object get(PCode self) {
163163
byte[] codestring = self.getCodestring();
164164
if (codestring == null) {
165-
// TODO: this is for the moment undefined
166165
codestring = new byte[0];
167166
}
168167
return factory().createBytes(codestring);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/FunctionBuiltins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
5454
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
5555
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
56+
import com.oracle.graal.python.nodes.code.GetFunctionCodeNode;
5657
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5758
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5859
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -245,8 +246,9 @@ Object doGeneric(Object object) {
245246
@GenerateNodeFactory
246247
public abstract static class GetCodeNode extends PythonBinaryBuiltinNode {
247248
@Specialization(guards = {"isNoValue(none)"})
248-
Object getCode(PFunction self, @SuppressWarnings("unused") PNone none) {
249-
return self.getCode();
249+
Object getCodeU(PFunction self, @SuppressWarnings("unused") PNone none,
250+
@Cached("create()") GetFunctionCodeNode getFunctionCodeNode) {
251+
return getFunctionCodeNode.execute(self);
250252
}
251253

252254
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)