Skip to content
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 .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ command line::

$ stone -h

Stone requires Python 3.

Alternative
-----------

Expand Down
1 change: 0 additions & 1 deletion mypy-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[mypy]
# follow_imports = False
ignore_missing_imports = True
show_none_errors = True
strict_optional = True
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/js_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
Comment on lines -8 to -14
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍 love to see this.

import argparse

from stone.backend import CodeBackend
from stone.backends.js_helpers import (
Expand Down
9 changes: 1 addition & 8 deletions stone/backends/js_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
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(
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/obj_c_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
import argparse

_cmdline_parser = argparse.ArgumentParser(
prog='objc-client-backend',
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/obj_c_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
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(
Expand Down
9 changes: 1 addition & 8 deletions stone/backends/python_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any

import argparse

# This will be at the top of the generated file.
base = """\
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
import argparse


_cmdline_parser = argparse.ArgumentParser(
Expand Down
9 changes: 1 addition & 8 deletions stone/backends/swift_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
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(
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/tsd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
import argparse

from stone.backend import CodeBackend
from stone.backends.tsd_helpers import (
Expand Down
8 changes: 1 addition & 7 deletions stone/backends/tsd_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
import argparse

from stone.ir import ApiNamespace
from stone.ir import (
Expand Down
8 changes: 1 addition & 7 deletions stone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
argparse = importlib.import_module(str('argparse')) # type: typing.Any
import argparse

# These backends come by default
_builtin_backends = (
Expand Down
10 changes: 2 additions & 8 deletions stone/frontend/ir_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks


_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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
import importlib
re = importlib.import_module(str('re')) # type: typing.Any
import re

from ..ir import (
Alias,
Expand Down
6 changes: 2 additions & 4 deletions stone/ir/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)]))
Expand Down
9 changes: 1 addition & 8 deletions test/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/python/typeshed/issues/756> and
# <https://github.com/python/mypy/issues/2536>.
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):
Expand Down
4 changes: 2 additions & 2 deletions test/test_python_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/test_tsd_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for the sake of this PR, but we should be able to update these to modern type hint syntax right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll run this one day: https://github.com/ilevkivskyi/com2ann

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we'll be able to unpin flake8


args = Mock()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ commands =
pylint --rcfile=.pylintrc setup.py example stone test

deps =
flake8
flake8<6
pylint
# This probably breaks on Windows. See
# <https://github.com/tox-dev/tox/issues/384>.
Expand Down