sympy/0001-Modify-literal-comparisons-as-per-python3.8-guidelines.patch
Robert-André Mauchin 7bb3831609 Add patches to fix build with Python 3.8 and Numpy 1.17
Signed-off-by: Robert-André Mauchin <zebob.m@gmail.com>
2019-08-24 16:24:31 +02:00

180 lines
7.8 KiB
Diff

From af7fab8860ee152a51b7c29a197b4a37b2f88a87 Mon Sep 17 00:00:00 2001
From: Vighnesh Shenoy <vighneshq@gmail.com>
Date: Fri, 7 Jun 2019 02:31:23 +0530
Subject: [PATCH] Modify literal comparisons as per python3.8 guidelines
This is in regards to issue #16973, Python 3.8 beta raises a warning
when comparing with string, int literals using is. The .travis.yml compileall
command has been added another flag to error if the convention is not followed.
A dummy test has been added in utilities/tests, this must cause the travis
build to fail in 3.8. If it does as expected, it can be removed, else the
compileall command will have to be changed.
---
.travis.yml | 5 ++++-
sympy/core/tests/test_containers.py | 2 +-
sympy/geometry/tests/test_plane.py | 2 +-
sympy/physics/vector/printing.py | 2 +-
sympy/plotting/plot.py | 6 +++---
sympy/polys/agca/modules.py | 4 ++--
sympy/solvers/diophantine.py | 2 +-
sympy/utilities/tests/test_travis.py | 6 ++++++
sympy/vector/coordsysrect.py | 4 ++--
9 files changed, 21 insertions(+), 12 deletions(-)
create mode 100644 sympy/utilities/tests/test_travis.py
diff --git a/.travis.yml b/.travis.yml
index 00b03d918fd..23f9ea8e15e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -283,6 +283,9 @@ install:
- pip install mpmath
# -We:invalid makes invalid escape sequences error in Python 3.6. See
# -#12028.
+ # SyntaxWarning flag for catching errors in Python3.8
+ # Issue - #16973. -We:invalid can be dropped from 3.8 onwards, but
+ # it needs to be there for earlier versions.
- |
if [[ "${TEST_SETUP}" == "true" ]]; then
# The install cycle below is to test installation on systems without
@@ -292,7 +295,7 @@ install:
~/.venv-no-setuptools/bin/pip uninstall -y setuptools;
~/.venv-no-setuptools/bin/python -We:invalid setup.py -q install;
fi
- python -We:invalid -m compileall -f -q sympy/;
+ python -We:invalid -We::SyntaxWarning -m compileall -f -q sympy/;
python -We:invalid setup.py -q install;
pip list --format=columns;
diff --git a/sympy/core/tests/test_containers.py b/sympy/core/tests/test_containers.py
index 79e3c9b85ba..af871de597a 100644
--- a/sympy/core/tests/test_containers.py
+++ b/sympy/core/tests/test_containers.py
@@ -52,7 +52,7 @@ def test_Tuple_concatenation():
def test_Tuple_equality():
- assert Tuple(1, 2) is not (1, 2)
+ assert not isinstance(Tuple(1, 2), tuple)
assert (Tuple(1, 2) == (1, 2)) is True
assert (Tuple(1, 2) != (1, 2)) is False
assert (Tuple(1, 2) == (1, 3)) is False
diff --git a/sympy/geometry/tests/test_plane.py b/sympy/geometry/tests/test_plane.py
index dec80b4bb99..959b9ff546a 100644
--- a/sympy/geometry/tests/test_plane.py
+++ b/sympy/geometry/tests/test_plane.py
@@ -187,7 +187,7 @@ def test_plane():
assert pl8.intersection(Plane(p1, normal_vector=(-1, -1, -11)))[0].equals(
Line3D(p1, direction_ratio=(1, -1, 0)))
assert pl3.random_point() in pl3
- assert len(pl8.intersection(Ray3D(Point3D(0, 2, 3), Point3D(1, 0, 3)))) is 0
+ assert len(pl8.intersection(Ray3D(Point3D(0, 2, 3), Point3D(1, 0, 3)))) == 0
# check if two plane are equals
assert pl6.intersection(pl6)[0].equals(pl6)
assert pl8.equals(Plane(p1, normal_vector=(0, 12, 0))) is False
diff --git a/sympy/physics/vector/printing.py b/sympy/physics/vector/printing.py
index 9d1e769a700..86f4159974a 100644
--- a/sympy/physics/vector/printing.py
+++ b/sympy/physics/vector/printing.py
@@ -152,7 +152,7 @@ class VectorLatexPrinter(LatexPrinter):
base = r"\ddddot{%s}" % base
else: # Fallback to standard printing
return LatexPrinter().doprint(der_expr)
- if len(base_split) is not 1:
+ if len(base_split) != 1:
base += '_' + base_split[1]
return base
diff --git a/sympy/plotting/plot.py b/sympy/plotting/plot.py
index 7ad4f550b2f..8d87b93be92 100644
--- a/sympy/plotting/plot.py
+++ b/sympy/plotting/plot.py
@@ -506,7 +506,7 @@ class LineOver1DRangeSeries(Line2DBaseSe
#at both ends. If there is a real value in between, then
#sample those points further.
elif p[1] is None and q[1] is None:
- if self.xscale is 'log':
+ if self.xscale == 'log':
xarray = np.logspace(p[0],q[0], 10)
else:
xarray = np.linspace(p[0], q[0], 10)
@@ -539,14 +539,14 @@ class LineOver1DRangeSeries(Line2DBaseSe
def get_points(self):
np = import_module('numpy')
if self.only_integers is True:
- if self.xscale is 'log':
+ if self.xscale == 'log':
list_x = np.logspace(int(self.start), int(self.end),
num=int(self.end) - int(self.start) + 1)
else:
list_x = np.linspace(int(self.start), int(self.end),
num=int(self.end) - int(self.start) + 1)
else:
- if self.xscale is 'log':
+ if self.xscale == 'log':
list_x = np.logspace(self.start, self.end, num=self.nb_of_points)
else:
list_x = np.linspace(self.start, self.end, num=self.nb_of_points)
diff --git a/sympy/polys/agca/modules.py b/sympy/polys/agca/modules.py
index aa296c52314..88e1618be11 100644
--- a/sympy/polys/agca/modules.py
+++ b/sympy/polys/agca/modules.py
@@ -26,7 +26,7 @@ from sympy.polys.agca.ideals import Idea
from sympy.polys.domains.field import Field
from sympy.polys.orderings import ProductOrder, monomial_key
from sympy.polys.polyerrors import CoercionFailed
-
+from sympy.core.basic import _aresame
# TODO
# - module saturation
@@ -357,7 +357,7 @@ class FreeModule(Module):
if len(tpl) != self.rank:
raise CoercionFailed
return FreeModuleElement(self, tpl)
- elif elem is 0:
+ elif _aresame(elem, 0):
return FreeModuleElement(self, (self.ring.convert(0),)*self.rank)
else:
raise CoercionFailed
diff --git a/sympy/solvers/diophantine.py b/sympy/solvers/diophantine.py
index 1c048d1e57d..2772b08e930 100644
--- a/sympy/solvers/diophantine.py
+++ b/sympy/solvers/diophantine.py
@@ -3183,7 +3183,7 @@ def power_representation(n, p, k, zeros=
'''Todd G. Will, "When Is n^2 a Sum of k Squares?", [online].
Available: https://www.maa.org/sites/default/files/Will-MMz-201037918.pdf'''
return
- if feasible is 1: # it's prime and k == 2
+ if feasible is not True: # it's prime and k == 2
yield prime_as_sum_of_two_squares(n)
return
diff --git a/sympy/utilities/tests/test_travis.py b/sympy/utilities/tests/test_travis.py
new file mode 100644
index 00000000000..f49eaa0cad1
--- /dev/null
+++ b/sympy/utilities/tests/test_travis.py
@@ -0,0 +1,6 @@
+def test_travis_issue_16986():
+ # If this causes the travis build to fail with Python3.8,
+ # then the changes made in PR #16986 are working as
+ # intended, and this file can be deleted.
+
+ assert int(1) is 1
diff --git a/sympy/vector/coordsysrect.py b/sympy/vector/coordsysrect.py
index a7b0e91c413..e629824c3cd 100644
--- a/sympy/vector/coordsysrect.py
+++ b/sympy/vector/coordsysrect.py
@@ -167,9 +167,9 @@ class CoordSys3D(Basic):
if isinstance(transformation, Lambda):
variable_names = ["x1", "x2", "x3"]
elif isinstance(transformation, Symbol):
- if transformation.name is 'spherical':
+ if transformation.name == 'spherical':
variable_names = ["r", "theta", "phi"]
- elif transformation.name is 'cylindrical':
+ elif transformation.name == 'cylindrical':
variable_names = ["r", "theta", "z"]
else:
variable_names = ["x", "y", "z"]