Skip to content

Commit

Permalink
Migrate mypy from setuf.cfg -> pyproject.toml. Starting running again…
Browse files Browse the repository at this point in the history
…st tests in CI
  • Loading branch information
timothycrosley committed Jun 21, 2021
1 parent 4cb72fa commit cd2e763
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 120 deletions.
4 changes: 2 additions & 2 deletions isort/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""All isort specific exception classes should be defined here"""
from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Type, Union

from .profiles import profiles

Expand Down Expand Up @@ -107,7 +107,7 @@ class LiteralParsingFailure(ISortError):
the given data structure.
"""

def __init__(self, code: str, original_error: Exception):
def __init__(self, code: str, original_error: Union[Exception, Type[Exception]]):
super().__init__(
f"isort failed to parse the given literal {code}. It's important to note "
"that isort literal sorting only supports simple literals parsable by "
Expand Down
2 changes: 1 addition & 1 deletion isort/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional, TextIO

try:
import colorama # type: ignore
import colorama
except ImportError:
colorama_unavailable = True
else:
Expand Down
7 changes: 6 additions & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from functools import lru_cache
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand All @@ -32,7 +33,6 @@

from . import sorting, stdlibs
from ._future import dataclass, field
from ._vendored import toml # type: ignore
from .exceptions import (
FormattingPluginDoesNotExist,
InvalidSettingsPath,
Expand All @@ -46,6 +46,11 @@
from .wrap_modes import WrapModes
from .wrap_modes import from_string as wrap_mode_from_string

if TYPE_CHECKING:
toml: Any
else:
from ._vendored import toml

_SHEBANG_RE = re.compile(br"^#!.*\bpython[23w]?\b")
CYTHON_EXTENSIONS = frozenset({"pyx", "pxd"})
SUPPORTED_EXTENSIONS = frozenset({"py", "pyi", *CYTHON_EXTENSIONS})
Expand Down
74 changes: 49 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bandit = "^1.6"
safety = "^1.8"
flake8-bugbear = "^19.8"
black = {version = "^20.08b1", allow-prereleases = true}
mypy = "^0.901"
mypy = "^0.902"
ipython = "^7.7"
pytest = "^6.0"
pytest-cov = "^2.7"
Expand Down Expand Up @@ -116,3 +116,15 @@ palette = {scheme = "isort"}
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
python_version = 3.6
strict = true
follow_imports = "silent"
exclude = "isort/_vendored|tests/unit/example_projects|tests/unit/example_crlf_file.py"

[[tool.mypy.overrides]]
module = "tests.*"
allow_untyped_defs = true
allow_incomplete_defs = true
allow_untyped_calls = true
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euxo pipefail

poetry run cruft check
poetry run mypy -p isort
poetry run mypy -p isort -p tests
poetry run black --target-version py36 --check .
poetry run isort --profile hug --check --diff isort/ tests/
poetry run isort --profile hug --check --diff example_*/
Expand Down
14 changes: 0 additions & 14 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
[mypy]
python_version = 3.6
strict = True
follow_imports = silent

[mypy-isort.isort._vendored.*]
ignore_errors = True

[mypy-test_isort]
strict_optional = False

[mypy-isort.isort]
strict_optional = False

[tool:pytest]
testpaths = tests

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/profiles/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def black_format(code: str, is_pyi: bool = False, line_length: int = 88) -> str:
return black.format_file_contents(
code,
fast=True,
mode=black.FileMode(
mode=black.FileMode( # type: ignore
is_pyi=is_pyi,
line_length=line_length,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@pytest.fixture
def imperfect(tmpdir) -> None:
def imperfect(tmpdir):
imperfect_file = tmpdir.join("test_needs_changes.py")
imperfect_file.write_text(imperfect_content, "utf8")
return imperfect_file
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_deprecated_finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def test_init(self):
assert FindersManager(settings.DEFAULT_CONFIG)

class ExceptionOnInit(finders.BaseFinder):
def __init__(*args, **kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
raise ValueError("test")

with patch(
"isort.deprecated.finders.FindersManager._default_finders_classes",
FindersManager._default_finders_classes + (ExceptionOnInit,),
FindersManager._default_finders_classes + (ExceptionOnInit,), # type: ignore
):
assert FindersManager(settings.Config(verbose=True))

Expand All @@ -59,14 +59,14 @@ class AbstractTestFinder:

@classmethod
def setup_class(cls):
cls.instance = cls.kind(settings.DEFAULT_CONFIG)
cls.instance = cls.kind(settings.DEFAULT_CONFIG) # type: ignore

def test_create(self):
assert self.kind(settings.DEFAULT_CONFIG)
assert self.kind(settings.DEFAULT_CONFIG) # type: ignore

def test_find(self):
self.instance.find("isort")
self.instance.find("")
self.instance.find("isort") # type: ignore
self.instance.find("") # type: ignore


class TestForcedSeparateFinder(AbstractTestFinder):
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_requirements_finder(tmpdir) -> None:
assert finder.find("flask") is None # package not in reqs
assert finder.find("deal") == sections.THIRDPARTY # vcs

assert len(finder.mapping) > 100
assert len(finder.mapping) > 100 # type: ignore
assert finder._normalize_name("deal") == "deal"
assert finder._normalize_name("Django") == "django" # lowercase
assert finder._normalize_name("django_haystack") == "haystack" # mapping
Expand All @@ -174,7 +174,7 @@ def test_pipfile_finder(tmpdir) -> None:
assert finder.find("flask") is None # package not in reqs
assert finder.find("deal") == sections.THIRDPARTY # vcs

assert len(finder.mapping) > 100
assert len(finder.mapping) > 100 # type: ignore
assert finder._normalize_name("deal") == "deal"
assert finder._normalize_name("Django") == "django" # lowercase
assert finder._normalize_name("django_haystack") == "haystack" # mapping
Expand Down
Loading

0 comments on commit cd2e763

Please sign in to comment.