From 5ab2aa8f2bf51b80fc9817c30a5355b9e3f13eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 11 Oct 2023 22:02:45 +0200 Subject: [PATCH] get rid of basestring and unicode (#115) --- cython/core/abelian_group.pyx | 4 ++-- cython/core/basic.pyx | 4 ---- cython/core/fundamental_group.pyx | 5 ++--- cython/core/triangulation.pyx | 5 ++--- twister/lib/main.py | 8 +------- 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/cython/core/abelian_group.pyx b/cython/core/abelian_group.pyx index bc473425d..d5a32ea8a 100644 --- a/cython/core/abelian_group.pyx +++ b/cython/core/abelian_group.pyx @@ -47,14 +47,14 @@ cdef class AbelianGroup(): except: raise ValueError('Elementary divisors must be given ' 'as a sequence.') - int_types = [int, long] + int_types = [int] if _within_sage: int_types += [sage.rings.integer.Integer] for c in self.divisors: assert type(c) in int_types and c >= 0,\ 'Elementary divisors must be non-negative integers.\n' for i in range(len(elementary_divisors) - 1): - n,m = elementary_divisors[i:i+2] + n, m = elementary_divisors[i:i+2] assert (n == m == 0) or (m % n == 0),\ 'The elementary divisors must form a divisibility chain\n' diff --git a/cython/core/basic.pyx b/cython/core/basic.pyx index e76bf016c..b87066cf6 100644 --- a/cython/core/basic.pyx +++ b/cython/core/basic.pyx @@ -122,10 +122,6 @@ class MsgIO(): msg_stream = MsgIO() -# string testing for Python 3 -basestring = unicode = str - - def to_str(s): return s.decode() diff --git a/cython/core/fundamental_group.pyx b/cython/core/fundamental_group.pyx index a83c3c2eb..50c1b2fda 100644 --- a/cython/core/fundamental_group.pyx +++ b/cython/core/fundamental_group.pyx @@ -71,9 +71,8 @@ cdef c_word_as_string(int *word, int num_generators, verbose_form): def word_as_list(word, int num_generators): - if not isinstance(word, basestring): - raise TypeError('Words must be represented ' - 'as Python strings.') + if not isinstance(word, str): + raise TypeError('Words must be represented as Python strings.') word_list = [] if num_generators > 26: for prefix, number in re.findall(r'([xX])(\d+)', word): diff --git a/cython/core/triangulation.pyx b/cython/core/triangulation.pyx index 1f1245999..f4961a7bc 100644 --- a/cython/core/triangulation.pyx +++ b/cython/core/triangulation.pyx @@ -95,9 +95,8 @@ cdef class Triangulation(): spec = getattr(spec, attr)() break if spec is not None and spec != 'empty': - # basestring was removed from python3 but cython supports it for all pythons - if not isinstance(spec, (basestring, bytes)): - raise TypeError(triangulation_help% + if not isinstance(spec, (str, bytes)): + raise TypeError(triangulation_help % self.__class__.__name__) self.get_triangulation(spec, remove_finite_vertices) if self.c_triangulation == NULL: diff --git a/twister/lib/main.py b/twister/lib/main.py index dfa9f0b17..378a2799c 100644 --- a/twister/lib/main.py +++ b/twister/lib/main.py @@ -8,12 +8,6 @@ from plink import LinkManager from .twister_core import build_bundle, build_splitting, twister_version -# Python 3 compatibility -try: - basestring -except NameError: # Python 3 - basestring = unicode = str - surface_database_path = os.path.join(os.path.dirname(__file__), 'surfaces') surface_database = set(os.listdir(surface_database_path)) version = twister_version() @@ -22,7 +16,7 @@ def _get_surface(surface): if isinstance(surface, tuple) and len(surface) == 2 and isinstance(surface[0], int) and isinstance(surface[1], int): return LP_surface(surface[0], surface[1]) - if isinstance(surface, basestring): + if isinstance(surface, str): # If surface is actually the contents of a surface file. if surface.startswith('# A Twister surface file'): return surface