diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 5bef62e7..b3a7532b 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -10,7 +10,7 @@ jobs: # https://github.com/actions/python-versions/blob/main/versions-manifest.json strategy: matrix: - os: [macos-latest, ubuntu-latest] + os: [macos-latest, ubuntu-20.04] python-version: [3.6, 3.7, 3.8, pypy-3.7] steps: - uses: actions/checkout@v2 @@ -21,7 +21,7 @@ jobs: - name: Install Requirements run: | python -m pip install --upgrade pip - pip install flake8 pylint pytest + pip install flake8==5.0.4 pylint pytest pip install -r requirements.txt pip install -r test/requirements.txt python setup.py install diff --git a/README.rst b/README.rst index 82f00804..2d3cc79f 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,8 @@ command line:: $ stone -h +Stone requires Python 3. + Alternative ----------- diff --git a/mypy-run.sh b/mypy-run.sh index 119f2fd8..f3434374 100755 --- a/mypy-run.sh +++ b/mypy-run.sh @@ -6,4 +6,3 @@ EXCLUDE='(^example/|^ez_setup\.py$|^setup\.py$)' INCLUDE=$(git ls-files "$@" | grep '\.py$' | grep -Ev "$EXCLUDE" | tr '\n' '\0' | xargs -0 | cat) MYPY_CMD=mypy $MYPY_CMD $INCLUDE -$MYPY_CMD --py2 $INCLUDE diff --git a/mypy.ini b/mypy.ini index 0fd85ed9..b2dd65f5 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,5 +1,4 @@ [mypy] # follow_imports = False ignore_missing_imports = True -show_none_errors = True strict_optional = True diff --git a/setup.py b/setup.py index 5977589a..ae41d750 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,7 @@ install_reqs += f.read().splitlines() setup_requires = [ - # Pin pytest-runner to 5.2.0, since 5.3.0 uses `find_namespaces` directive, not supported in - # Python 2.7 - 'pytest-runner == 5.2.0', + 'pytest-runner == 5.3.2', ] # WARNING: This imposes limitations on test/requirements.txt such that the diff --git a/stone/backends/js_client.py b/stone/backends/js_client.py index 14076850..728e38ae 100644 --- a/stone/backends/js_client.py +++ b/stone/backends/js_client.py @@ -5,13 +5,7 @@ import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression from stone.ir import ApiNamespace -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse from stone.backend import CodeBackend from stone.backends.js_helpers import ( diff --git a/stone/backends/js_types.py b/stone/backends/js_types.py index 778bf11c..aa775c9e 100644 --- a/stone/backends/js_types.py +++ b/stone/backends/js_types.py @@ -22,14 +22,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any - +import argparse _cmdline_parser = argparse.ArgumentParser(prog='js-types-backend') _cmdline_parser.add_argument( diff --git a/stone/backends/obj_c_client.py b/stone/backends/obj_c_client.py index c86253fa..91587aad 100644 --- a/stone/backends/obj_c_client.py +++ b/stone/backends/obj_c_client.py @@ -37,13 +37,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse _cmdline_parser = argparse.ArgumentParser( prog='objc-client-backend', diff --git a/stone/backends/obj_c_types.py b/stone/backends/obj_c_types.py index df07b445..350fd6ce 100644 --- a/stone/backends/obj_c_types.py +++ b/stone/backends/obj_c_types.py @@ -57,13 +57,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse _cmdline_parser = argparse.ArgumentParser(prog='obj-c-types-backend') _cmdline_parser.add_argument( diff --git a/stone/backends/python_client.py b/stone/backends/python_client.py index edc88fd3..2c2a2729 100644 --- a/stone/backends/python_client.py +++ b/stone/backends/python_client.py @@ -31,14 +31,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any - +import argparse # This will be at the top of the generated file. base = """\ diff --git a/stone/backends/swift_client.py b/stone/backends/swift_client.py index 6c2adfce..9228729b 100644 --- a/stone/backends/swift_client.py +++ b/stone/backends/swift_client.py @@ -25,13 +25,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse _cmdline_parser = argparse.ArgumentParser( diff --git a/stone/backends/swift_types.py b/stone/backends/swift_types.py index 572e4407..6e2baa9e 100644 --- a/stone/backends/swift_types.py +++ b/stone/backends/swift_types.py @@ -35,14 +35,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any - +import argparse _cmdline_parser = argparse.ArgumentParser(prog='swift-types-backend') _cmdline_parser.add_argument( diff --git a/stone/backends/tsd_client.py b/stone/backends/tsd_client.py index 6c07b4f7..b51b6e78 100644 --- a/stone/backends/tsd_client.py +++ b/stone/backends/tsd_client.py @@ -7,13 +7,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse from stone.backend import CodeBackend from stone.backends.tsd_helpers import ( diff --git a/stone/backends/tsd_types.py b/stone/backends/tsd_types.py index 3800c5f1..79690390 100644 --- a/stone/backends/tsd_types.py +++ b/stone/backends/tsd_types.py @@ -10,13 +10,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse from stone.ir import ApiNamespace from stone.ir import ( diff --git a/stone/cli.py b/stone/cli.py index d6004ce7..53a1ac13 100644 --- a/stone/cli.py +++ b/stone/cli.py @@ -26,13 +26,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any +import argparse # These backends come by default _builtin_backends = ( diff --git a/stone/frontend/ir_generator.py b/stone/frontend/ir_generator.py index f761ce5d..9a207416 100644 --- a/stone/frontend/ir_generator.py +++ b/stone/frontend/ir_generator.py @@ -9,19 +9,13 @@ try: from inspect import getfullargspec as get_args except ImportError: - from inspect import getargspec as get_args + from inspect import getargspec as get_args # type: ignore _MYPY = False if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -re = importlib.import_module(str('re')) # type: typing.Any +import re from ..ir import ( Alias, diff --git a/stone/ir/data_types.py b/stone/ir/data_types.py index 0bd98dea..858c1510 100644 --- a/stone/ir/data_types.py +++ b/stone/ir/data_types.py @@ -689,7 +689,7 @@ def set_default(self, default): @property def default(self): if not self.has_default: - raise Exception('Type has no default') + raise ValueError('Type has no default') else: return self._default @@ -1382,7 +1382,7 @@ def __init__(self, name, namespace, ast_node, closed): # TODO: Why is this a different signature than the parent? Is this # intentional? - def set_attributes(self, doc, fields, # pylint: disable=arguments-differ + def set_attributes(self, doc, fields, parent_type=None, catch_all_field=None): """ :param UnionField catch_all_field: The field designated as the @@ -1475,7 +1475,6 @@ def _add_example(self, example): ) # TODO: are we always guaranteed at least one field? - # pylint: disable=undefined-loop-variable try: field.data_type.check_example(example_field) except InvalidSpec as e: @@ -1581,7 +1580,6 @@ def get_json_val(dt, val): raise AssertionError('No example for label %r' % label) # TODO: are we always guaranteed at least one field? - # pylint: disable=undefined-loop-variable assert is_void_type(field.data_type) return Example( field.name, field.doc, OrderedDict([('.tag', field.name)])) diff --git a/test/test_backend.py b/test/test_backend.py index 56a045ce..6a911cd4 100755 --- a/test/test_backend.py +++ b/test/test_backend.py @@ -29,14 +29,7 @@ if _MYPY: import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression -# Hack to get around some of Python 2's standard library modules that -# accept ascii-encodable unicode literals in lieu of strs, but where -# actually passing such literals results in errors with mypy --py2. See -# and -# . -import importlib -argparse = importlib.import_module(str('argparse')) # type: typing.Any - +import argparse class _Tester(CodeBackend): """A no-op backend used to test helper methods.""" def generate(self, api): diff --git a/test/test_python_gen.py b/test/test_python_gen.py index 6465f0a7..578ac0b1 100755 --- a/test/test_python_gen.py +++ b/test/test_python_gen.py @@ -1245,8 +1245,8 @@ def test_struct_equality_with_value(self): self.assertNotEqual(s, s_unequal) def test_struct_equality_with_different_types(self): - """Structs of different types that do not have an inheritance relationship are not considered - equal to each other.""" + """Structs of different types that do not have an inheritance relationship are not + considered equal to each other.""" s = self.decode(bv.Struct(self.ns.S), json.dumps({'f': 'F'})) t = self.decode(bv.Struct(self.ns.T), json.dumps({'f': 'F'})) self.assertNotEqual(s, t) diff --git a/test/test_tsd_types.py b/test/test_tsd_types.py index 49b8dda9..8595f76f 100644 --- a/test/test_tsd_types.py +++ b/test/test_tsd_types.py @@ -27,7 +27,7 @@ from test.backend_test_util import _mock_output -def _make_backend(target_folder_path, template_path, custom_args=None): +def _make_backend(target_folder_path, template_path, custom_args=None): # type: ignore # type: (typing.Text, typing.Text, typing.List) -> TSDTypesBackend args = Mock() diff --git a/tox.ini b/tox.ini index b8ef1502..a694f6ec 100644 --- a/tox.ini +++ b/tox.ini @@ -38,7 +38,7 @@ commands = pylint --rcfile=.pylintrc setup.py example stone test deps = - flake8 + flake8<6 pylint # This probably breaks on Windows. See # .