Skip to content

Commit

Permalink
Merge pull request beeware#970 from whydoubt/py37
Browse files Browse the repository at this point in the history
Python 3.7
  • Loading branch information
freakboy3742 authored Aug 18, 2019
2 parents 6a0967e + a8ba9f6 commit 235e838
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 54 deletions.
3 changes: 3 additions & 0 deletions beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pull_request:
- py3.6:
name: Python 3.6 tests
image: pybee/voc-py36
- py3.7:
name: Python 3.7 tests
image: pybee/voc-py37
profile: hi-cpu
push:
- smoke-test:
Expand Down
6 changes: 5 additions & 1 deletion python/common/org/Python.java
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,11 @@ public static org.python.types.Tuple divmod(org.python.Object a, org.python.Obje
)
public static org.python.Object enumerate(org.python.Object items, org.python.Object start) {
if (items == null) {
throw new org.python.exceptions.TypeError("Required argument 'iterable' (pos 1) not found");
if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("Required argument 'iterable' (pos 1) not found");
} else {
throw new org.python.exceptions.TypeError("enumerate() missing required argument 'iterable' (pos 1)");
}
}
org.python.Object index = org.python.types.Int.getInt(0);
if (start != null) {
Expand Down
6 changes: 5 additions & 1 deletion python/common/org/python/exceptions/BaseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ private static org.python.types.Tuple buildTuple(org.python.Object[] args) {
__doc__ = "Return repr(self)."
)
public org.python.Object __repr__() {
return new org.python.types.Str(this.getClass().getSimpleName() + this.args.toString());
if (org.Python.VERSION < 0x03070000 || this.args.value.size() != 1) {
return new org.python.types.Str(this.getClass().getSimpleName() + this.args.toString());
} else {
return new org.python.types.Str(this.getClass().getSimpleName() + "(" + this.args.value.get(0).__repr__() + ")");
}
}

@org.python.Method(
Expand Down
4 changes: 3 additions & 1 deletion python/common/org/python/types/Bool.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public Bool(org.python.Object[] args, java.util.Map<java.lang.String, org.python
this.value = false;
} else if (args.length == 1) {
this.value = args[0].toBoolean();
} else {
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("bool() takes at most 1 argument (" + args.length + " given)");
} else {
throw new org.python.exceptions.TypeError("bool expected at most 1 arguments, got " + args.length);
}
}
// public org.python.Object __new__() {
Expand Down
8 changes: 5 additions & 3 deletions python/common/org/python/types/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,13 @@ public org.python.Object count(org.python.Object sub, org.python.Object start, o
} else if (sub instanceof org.python.types.Bytes) {
sub_array = ((org.python.types.Bytes) sub).value;
} else {
String error_message = "a bytes-like object is required, not '" + sub.typeName() + "'\n";
if (org.Python.VERSION < 0x03050000) {
error_message = "'" + sub.typeName() + "' does not support the buffer interface\n";
throw new org.python.exceptions.TypeError("'" + sub.typeName() + "' does not support the buffer interface");
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("a bytes-like object is required, not '" + sub.typeName() + "'");
} else {
throw new org.python.exceptions.TypeError("argument should be integer or bytes-like object, not '" + sub.typeName() + "'");
}
throw new org.python.exceptions.TypeError(error_message);
}
//If the sub string is longer than the value string a match cannot exist
if (sub_array.length > this.value.length) {
Expand Down
3 changes: 2 additions & 1 deletion python/common/org/python/types/DictItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public org.python.Object __iter__() {
args = {"index"}
)
public org.python.Object __getitem__(org.python.Object index) {
if (index instanceof org.python.types.Int || index instanceof org.python.types.Bool) {
if (org.Python.VERSION < 0x03070000 &&
(index instanceof org.python.types.Int || index instanceof org.python.types.Bool)) {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object does not support indexing");
} else {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object is not subscriptable");
Expand Down
3 changes: 2 additions & 1 deletion python/common/org/python/types/DictKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public boolean __delattr_null(java.lang.String name) {
args = {"index"}
)
public org.python.Object __getitem__(org.python.Object index) {
if (index instanceof org.python.types.Int || index instanceof org.python.types.Bool) {
if (org.Python.VERSION < 0x03070000 &&
(index instanceof org.python.types.Int || index instanceof org.python.types.Bool)) {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object does not support indexing");
} else {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object is not subscriptable");
Expand Down
3 changes: 2 additions & 1 deletion python/common/org/python/types/DictValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public org.python.Object __iter__() {
args = {"index"}
)
public org.python.Object __getitem__(org.python.Object index) {
if (index instanceof org.python.types.Int || index instanceof org.python.types.Bool) {
if (org.Python.VERSION < 0x03070000 &&
(index instanceof org.python.types.Int || index instanceof org.python.types.Bool)) {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object does not support indexing");
} else {
throw new org.python.exceptions.TypeError("'" + this.typeName() + "' object is not subscriptable");
Expand Down
4 changes: 3 additions & 1 deletion python/common/org/python/types/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public Float(org.python.Object[] args, java.util.Map<java.lang.String, org.pytho
"float() argument must be a string or a number, not '" + args[0].typeName() + "'"
);
}
} else {
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("float() takes at most 1 argument (" + args.length + " given)");
} else {
throw new org.python.exceptions.TypeError("float expected at most 1 arguments, got " + args.length);
}
}

Expand Down
3 changes: 2 additions & 1 deletion python/common/org/python/types/FrozenSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public org.python.types.Str __repr__() {
args = {"index"}
)
public org.python.Object __getitem__(org.python.Object index) {
if (index instanceof org.python.types.Int || index instanceof org.python.types.Bool) {
if (org.Python.VERSION < 0x03070000 &&
(index instanceof org.python.types.Int || index instanceof org.python.types.Bool)) {
throw new org.python.exceptions.TypeError("'frozenset' object does not support indexing");
} else {
throw new org.python.exceptions.TypeError("'frozenset' object is not subscriptable");
Expand Down
4 changes: 3 additions & 1 deletion python/common/org/python/types/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public List(org.python.Object[] args, java.util.Map<java.lang.String, org.python
}
this.value = generated;
}
} else {
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("list() takes at most 1 argument (" + args.length + " given)");
} else {
throw new org.python.exceptions.TypeError("list expected at most 1 arguments, got " + args.length);
}
}

Expand Down
10 changes: 6 additions & 4 deletions python/common/org/python/types/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public Object(java.lang.String msg) {
)
public Object(org.python.Object[] args, java.util.Map<java.lang.String, org.python.Object> kwargs) {
this(org.python.types.Type.Origin.PYTHON, null);
if (args != null && args.length > 0) {
throw new org.python.exceptions.TypeError("object() takes no parameters");
} else if (kwargs != null && kwargs.size() > 0) {
throw new org.python.exceptions.TypeError("object() takes no parameters");
if ((args != null && args.length > 0) || (kwargs != null && kwargs.size() > 0)) {
if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("object() takes no parameters");
} else {
throw new org.python.exceptions.TypeError("object() takes no arguments");
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion python/common/org/python/types/Set.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public org.python.types.Str __format__(org.python.Object format_string) {
args = {"index"}
)
public org.python.Object __getitem__(org.python.Object index) {
if (index instanceof org.python.types.Int || index instanceof org.python.types.Bool) {
if (org.Python.VERSION < 0x03070000 &&
(index instanceof org.python.types.Int || index instanceof org.python.types.Bool)) {
throw new org.python.exceptions.TypeError("'set' object does not support indexing");
} else {
throw new org.python.exceptions.TypeError("'set' object is not subscriptable");
Expand Down
10 changes: 8 additions & 2 deletions python/common/org/python/types/Str.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ public org.python.Object __add__(org.python.Object other) {
}
if (org.Python.VERSION < 0x03060000) {
throw new org.python.exceptions.TypeError("Can't convert '" + other.typeName() + "' object to str implicitly");
} else {
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("must be str, not " + other.typeName());
} else {
throw new org.python.exceptions.TypeError("can only concatenate str (not \"" + other.typeName() + "\") to str");
}
}

Expand Down Expand Up @@ -1771,7 +1773,11 @@ public org.python.Object upper() {
)
public org.python.Object zfill(org.python.Object width) {
if (width == null) {
throw new org.python.exceptions.TypeError("zfill() takes exactly 1 argument (0 given)");
if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("zfill() takes exactly 1 argument (0 given)");
} else {
throw new org.python.exceptions.TypeError("zfill() takes exactly one argument (0 given)");
}
} else if (width instanceof org.python.types.Float) {
throw new org.python.exceptions.TypeError("integer argument expected, got float");
} else if (!(width instanceof org.python.types.Int)) {
Expand Down
4 changes: 3 additions & 1 deletion python/common/org/python/types/Tuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public Tuple(org.python.Object[] args, java.util.Map<java.lang.String, org.pytho
}
this.value = generated;
}
} else {
} else if (org.Python.VERSION < 0x03070000) {
throw new org.python.exceptions.TypeError("tuple() takes at most 1 argument (" + args.length + " given)");
} else {
throw new org.python.exceptions.TypeError("tuple expected at most 1 arguments, got " + args.length);
}
}

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Software Development',
'Topic :: Utilities',
Expand Down
64 changes: 32 additions & 32 deletions tests/datatypes/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,22 +636,22 @@ class BinaryBytesOperationTests(BinaryOperationTestCase, TranspileTestCase):
]

not_implemented_versions = {
'test_modulo_None': (3.5, 3.6),
'test_modulo_NotImplemented': (3.5, 3.6),
'test_modulo_bool': (3.5, 3.6),
'test_modulo_bytearray': (3.5, 3.6),
'test_modulo_bytes': (3.5, 3.6),
'test_modulo_class': (3.5, 3.6),
'test_modulo_float': (3.5, 3.6),
'test_modulo_frozenset': (3.5, 3.6),
'test_modulo_int': (3.5, 3.6),
'test_modulo_list': (3.5, 3.6),
'test_modulo_range': (3.5, 3.6),
'test_modulo_set': (3.5, 3.6),
'test_modulo_slice': (3.5, 3.6),
'test_modulo_str': (3.5, 3.6),
'test_modulo_tuple': (3.5, 3.6),
'test_modulo_obj': (3.5, 3.6),
'test_modulo_None': (3.5, 3.6, 3.7),
'test_modulo_NotImplemented': (3.5, 3.6, 3.7),
'test_modulo_bool': (3.5, 3.6, 3.7),
'test_modulo_bytearray': (3.5, 3.6, 3.7),
'test_modulo_bytes': (3.5, 3.6, 3.7),
'test_modulo_class': (3.5, 3.6, 3.7),
'test_modulo_float': (3.5, 3.6, 3.7),
'test_modulo_frozenset': (3.5, 3.6, 3.7),
'test_modulo_int': (3.5, 3.6, 3.7),
'test_modulo_list': (3.5, 3.6, 3.7),
'test_modulo_range': (3.5, 3.6, 3.7),
'test_modulo_set': (3.5, 3.6, 3.7),
'test_modulo_slice': (3.5, 3.6, 3.7),
'test_modulo_str': (3.5, 3.6, 3.7),
'test_modulo_tuple': (3.5, 3.6, 3.7),
'test_modulo_obj': (3.5, 3.6, 3.7),
}


Expand All @@ -663,22 +663,22 @@ class InplaceBytesOperationTests(InplaceOperationTestCase, TranspileTestCase):
]

not_implemented_versions = {
'test_modulo_None': (3.5, 3.6),
'test_modulo_NotImplemented': (3.5, 3.6),
'test_modulo_bool': (3.5, 3.6),
'test_modulo_bytearray': (3.5, 3.6),
'test_modulo_bytes': (3.5, 3.6),
'test_modulo_class': (3.5, 3.6),
'test_modulo_float': (3.5, 3.6),
'test_modulo_frozenset': (3.5, 3.6),
'test_modulo_int': (3.5, 3.6),
'test_modulo_list': (3.5, 3.6),
'test_modulo_range': (3.5, 3.6),
'test_modulo_set': (3.5, 3.6),
'test_modulo_slice': (3.5, 3.6),
'test_modulo_str': (3.5, 3.6),
'test_modulo_tuple': (3.5, 3.6),
'test_modulo_obj': (3.5, 3.6),
'test_modulo_None': (3.5, 3.6, 3.7),
'test_modulo_NotImplemented': (3.5, 3.6, 3.7),
'test_modulo_bool': (3.5, 3.6, 3.7),
'test_modulo_bytearray': (3.5, 3.6, 3.7),
'test_modulo_bytes': (3.5, 3.6, 3.7),
'test_modulo_class': (3.5, 3.6, 3.7),
'test_modulo_float': (3.5, 3.6, 3.7),
'test_modulo_frozenset': (3.5, 3.6, 3.7),
'test_modulo_int': (3.5, 3.6, 3.7),
'test_modulo_list': (3.5, 3.6, 3.7),
'test_modulo_range': (3.5, 3.6, 3.7),
'test_modulo_set': (3.5, 3.6, 3.7),
'test_modulo_slice': (3.5, 3.6, 3.7),
'test_modulo_str': (3.5, 3.6, 3.7),
'test_modulo_tuple': (3.5, 3.6, 3.7),
'test_modulo_obj': (3.5, 3.6, 3.7),
}

is_flakey = [
Expand Down
8 changes: 6 additions & 2 deletions tests/stdlib/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
from unittest import expectedFailure

from ..utils import TranspileTestCase
from ..utils import TranspileTestCase, NotImplementedToExpectedFailure


class TimeModuleTests(TranspileTestCase):
class TimeModuleTests(NotImplementedToExpectedFailure, TranspileTestCase):

#######################################################
# _STRUCT_TM_ITEMS
Expand Down Expand Up @@ -311,3 +311,7 @@ def test_tzset(self):
import time
print(time.tzset())
""")

not_implemented_versions = {
'test_clock': (3.7, )
}

0 comments on commit 235e838

Please sign in to comment.