Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of basestring and unicode #115

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cython/core/abelian_group.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 0 additions & 4 deletions cython/core/basic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class MsgIO():
msg_stream = MsgIO()


# string testing for Python 3
basestring = unicode = str


def to_str(s):
return s.decode()

Expand Down
5 changes: 2 additions & 3 deletions cython/core/fundamental_group.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions cython/core/triangulation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 1 addition & 7 deletions twister/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down