diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index e31b1b82..4f2ce23d 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -35,5 +35,5 @@ jobs: - name: Run MyPy if: matrix.python-version != 'pypy-3.7' run: | - pip install enum34 mypy types-six + pip install mypy typed-ast ./mypy-run.sh diff --git a/README.rst b/README.rst index 2d3cc79f..b5f9f6a4 100644 --- a/README.rst +++ b/README.rst @@ -32,10 +32,10 @@ Alternative ----------- If you choose not to install ``stone`` using the method above, you will need -to ensure that you have the Python packages ``ply`` and ``six``, which can be +to ensure that you have the Python package ``ply``, which can be installed through ``pip``:: - $ pip install "ply>=3.4" "six>=1.3.0" "typing>=3.5.2" + $ pip install "ply>=3.4" "typing>=3.5.2" If the ``stone`` package is in your PYTHONPATH, you can replace ``stone`` with ``python -m stone.cli`` as follows:: diff --git a/requirements.txt b/requirements.txt index d2431b5c..ad70922d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ ply>= 3.4 -six>= 1.12.0 packaging>=21.0 Jinja2>= 3.0.3 diff --git a/stone/backends/obj_c_types.py b/stone/backends/obj_c_types.py index ae485141..e11b4239 100644 --- a/stone/backends/obj_c_types.py +++ b/stone/backends/obj_c_types.py @@ -2,8 +2,6 @@ import os import shutil -import six - from stone.backends.obj_c import ( base_file_comment, comment_prefix, @@ -915,7 +913,7 @@ def _determine_validator_type(self, data_type, value, has_default): if data_type.min_length else 'nil'), ('maxLength', '@({})'.format(data_type.max_length) if data_type.max_length else 'nil'), - ('pattern', '@"{}"'.format(six.ensure_str(pattern)) + ('pattern', '@"{}"'.format(str(pattern)) if pattern else 'nil'), ])) diff --git a/stone/backends/python_rsrc/stone_serializers.py b/stone/backends/python_rsrc/stone_serializers.py index 7eac8506..0d03435d 100644 --- a/stone/backends/python_rsrc/stone_serializers.py +++ b/stone/backends/python_rsrc/stone_serializers.py @@ -20,8 +20,6 @@ import re import time -import six - from stone.backends.python_rsrc import ( stone_base as bb, stone_validators as bv, @@ -658,7 +656,7 @@ def decode_union(self, data_type, obj): else: raise bv.ValidationError("expected string or object, got %s" % bv.generic_type_name(obj)) - return data_type.definition(six.ensure_str(tag), val) + return data_type.definition(str(tag), val) def decode_union_dict(self, data_type, obj): if '.tag' not in obj: @@ -785,7 +783,7 @@ def decode_union_old(self, data_type, obj): else: raise bv.ValidationError("expected string or object, got %s" % bv.generic_type_name(obj)) - return data_type.definition(six.ensure_str(tag), val) + return data_type.definition(str(tag), val) def decode_struct_tree(self, data_type, obj): """ @@ -1003,45 +1001,7 @@ def _findall(text, substr): # Every 28 years the calendar repeats, except through century leap years # where it's 6 years. But only if you're using the Gregorian calendar. ;) def _strftime(dt, fmt): - try: - return dt.strftime(fmt) - except ValueError: - if not six.PY2 or dt.year > 1900: - raise - - if _ILLEGAL_S.search(fmt): - raise TypeError("This strftime implementation does not handle %s") - - year = dt.year - - # For every non-leap year century, advance by 6 years to get into the - # 28-year repeat cycle - delta = 2000 - year - off = 6 * (delta // 100 + delta // 400) - year = year + off - - # Move to around the year 2000 - year = year + ((2000 - year) // 28) * 28 - timetuple = dt.timetuple() - s1 = time.strftime(fmt, (year,) + timetuple[1:]) - sites1 = _findall(s1, str(year)) - - s2 = time.strftime(fmt, (year + 28,) + timetuple[1:]) - sites2 = _findall(s2, str(year + 28)) - - sites = [] - - for site in sites1: - if site in sites2: - sites.append(site) - - s = s1 - syear = '%4d' % (dt.year,) - - for site in sites: - s = s[:site] + syear + s[site + 4:] - - return s + return dt.strftime(fmt) try: diff --git a/stone/backends/python_rsrc/stone_validators.py b/stone/backends/python_rsrc/stone_validators.py index dc553ee8..3844baa9 100644 --- a/stone/backends/python_rsrc/stone_validators.py +++ b/stone/backends/python_rsrc/stone_validators.py @@ -14,8 +14,6 @@ import re from abc import ABCMeta, abstractmethod -import six - _MYPY = False if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression @@ -328,17 +326,10 @@ def __init__(self, min_length=None, max_length=None, pattern=None): def validate(self, val): """ A unicode string of the correct length and pattern will pass validation. - In PY2, we enforce that a str type must be valid utf-8, and a unicode - string will be returned. """ if not isinstance(val, str): raise ValidationError("'%s' expected to be a string, got %s" % (get_value_string(val), generic_type_name(val))) - if not six.PY3 and isinstance(val, str): - try: - val = val.decode('utf-8') - except UnicodeDecodeError: - raise ValidationError("'%s' was not valid utf-8") if self.max_length is not None and len(val) > self.max_length: raise ValidationError("'%s' must be at most %d characters, got %d" diff --git a/stone/backends/swift_types.py b/stone/backends/swift_types.py index f07851ca..38393c16 100644 --- a/stone/backends/swift_types.py +++ b/stone/backends/swift_types.py @@ -2,7 +2,6 @@ import os import shutil -import six import jinja2 import textwrap @@ -304,7 +303,7 @@ def _determine_validator_type(self, data_type, value): self._func_args([ ("minLength", data_type.min_length), ("maxLength", data_type.max_length), - ("pattern", '"{}"'.format(six.ensure_str(pat)) if pat else None), + ("pattern", '"{}"'.format(str(pat)) if pat else None), ]) ) else: diff --git a/test/test_python_gen.py b/test/test_python_gen.py index 1e8dfa35..69930064 100755 --- a/test/test_python_gen.py +++ b/test/test_python_gen.py @@ -10,8 +10,6 @@ import sys import unittest -import six - import stone.backends.python_rsrc.stone_base as bb import stone.backends.python_rsrc.stone_serializers as ss import stone.backends.python_rsrc.stone_validators as bv @@ -655,7 +653,7 @@ def __init__(self): pass assert bv.type_name_with_module(Foo) == "test.test_python_gen.Foo" - assert bv.type_name_with_module(int) == "builtins.int" if six.PY3 else "__builtin__.int" + assert bv.type_name_with_module(int) == "builtins.int" test_spec = """\