summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2021-06-20 22:54:14 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2021-06-20 22:54:14 -0700
commitcd2e7636affca6bd7a3856cb6ed23b4f33eaac9f (patch)
tree6ed32f7516a7679b7f96b5b143ba7dbe0ad26807
parent4cb72fa93fdcd78df00687de7cd91428ab0fdc93 (diff)
downloadisort-cd2e7636affca6bd7a3856cb6ed23b4f33eaac9f.tar.gz
Migrate mypy from setuf.cfg -> pyproject.toml. Starting running against tests in CI
-rw-r--r--isort/exceptions.py4
-rw-r--r--isort/format.py2
-rw-r--r--isort/settings.py7
-rw-r--r--poetry.lock74
-rw-r--r--pyproject.toml14
-rwxr-xr-xscripts/lint.sh2
-rw-r--r--setup.cfg14
-rw-r--r--tests/unit/profiles/test_black.py2
-rw-r--r--tests/unit/test_api.py2
-rw-r--r--tests/unit/test_deprecated_finders.py16
-rw-r--r--tests/unit/test_exceptions.py24
-rw-r--r--tests/unit/test_isort.py89
-rw-r--r--tests/unit/test_main.py22
-rw-r--r--tests/unit/test_regressions.py2
-rw-r--r--tests/unit/test_settings.py4
15 files changed, 158 insertions, 120 deletions
diff --git a/isort/exceptions.py b/isort/exceptions.py
index 275dc424..e5eeceaa 100644
--- a/isort/exceptions.py
+++ b/isort/exceptions.py
@@ -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
@@ -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 "
diff --git a/isort/format.py b/isort/format.py
index 4de09a42..3a7c1e0b 100644
--- a/isort/format.py
+++ b/isort/format.py
@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Optional, TextIO
try:
- import colorama # type: ignore
+ import colorama
except ImportError:
colorama_unavailable = True
else:
diff --git a/isort/settings.py b/isort/settings.py
index b17488bf..d04dd838 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -15,6 +15,7 @@ import sys
from functools import lru_cache
from pathlib import Path
from typing import (
+ TYPE_CHECKING,
Any,
Callable,
Dict,
@@ -32,7 +33,6 @@ from warnings import warn
from . import sorting, stdlibs
from ._future import dataclass, field
-from ._vendored import toml # type: ignore
from .exceptions import (
FormattingPluginDoesNotExist,
InvalidSettingsPath,
@@ -46,6 +46,11 @@ from .sections import FIRSTPARTY, FUTURE, LOCALFOLDER, STDLIB, THIRDPARTY
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})
diff --git a/poetry.lock b/poetry.lock
index 27358a06..92ff4945 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -855,7 +855,7 @@ mkdocs-material = ">=5.0.0"
[[package]]
name = "mypy"
-version = "0.901"
+version = "0.902"
description = "Optional static typing for Python"
category = "dev"
optional = false
@@ -1593,6 +1593,14 @@ dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)"]
doc = ["mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=5.4.0,<6.0.0)", "markdown-include (>=0.5.1,<0.6.0)"]
[[package]]
+name = "types-colorama"
+version = "0.4.2"
+description = "Typing stubs for colorama"
+category = "dev"
+optional = false
+python-versions = "*"
+
+[[package]]
name = "types-pkg-resources"
version = "0.1.3"
description = "Typing stubs for pkg_resources"
@@ -1601,6 +1609,14 @@ optional = false
python-versions = "*"
[[package]]
+name = "types-toml"
+version = "0.1.3"
+description = "Typing stubs for toml"
+category = "dev"
+optional = false
+python-versions = "*"
+
+[[package]]
name = "typing-extensions"
version = "3.10.0.0"
description = "Backported and Experimental Type Hints for Python 3.5+"
@@ -1739,7 +1755,7 @@ requirements_deprecated_finder = ["pipreqs", "pip-api"]
[metadata]
lock-version = "1.1"
python-versions = ">=3.6.1,<4.0"
-content-hash = "f9e26ab53135b8de55863d9138e5ebd78764d8d5172199ad95c516b8383b4bee"
+content-hash = "c73791ac0cce25c94e949750728fbe4f48d4dfadacc874f781dcc4d8266531af"
[metadata.files]
appdirs = [
@@ -2130,29 +2146,29 @@ mkdocs-material-extensions = [
{file = "mkdocs_material_extensions-1.0.1-py3-none-any.whl", hash = "sha256:d90c807a88348aa6d1805657ec5c0b2d8d609c110e62b9dce4daf7fa981fa338"},
]
mypy = [
- {file = "mypy-0.901-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:91211acf1485a1db0b1261bc5f9ed450cba3c0dfd8da0a6680e94827591e34d7"},
- {file = "mypy-0.901-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c8bc628961cca4335ac7d1f2ed59b7125d9252fe4c78c3d66d30b50162359c99"},
- {file = "mypy-0.901-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:4a622faa3be76114cdce009f8ec173401494cf9e8f22713e7ae75fee9d906ab3"},
- {file = "mypy-0.901-cp35-cp35m-win_amd64.whl", hash = "sha256:8183561bfd950e93eeab8379ae5ec65873c856f5b58498d23aa8691f74c86030"},
- {file = "mypy-0.901-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:da914faaa80c25f463913da6db12adba703822a768f452f29f75b40bb4357139"},
- {file = "mypy-0.901-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:307a6c047596d768c3d689734307e47a91596eb9dbb67cfdf7d1fd9117b27f13"},
- {file = "mypy-0.901-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:a85c6759dcc6a9884131fa06a037bd34352aa3947e7f5d9d5a35652cc3a44bcd"},
- {file = "mypy-0.901-cp36-cp36m-win_amd64.whl", hash = "sha256:9941b685807b60c58020bb67b3217c9df47820dcd00425f55cdf71f31d3c42d9"},
- {file = "mypy-0.901-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:08cf1f31029612e1008a9432337ca4b1fbac989ff7c8200e2c9ec42705cd4c7b"},
- {file = "mypy-0.901-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bc61153eb4df769538bb4a6e1045f59c2e6119339690ec719feeacbfc3809e89"},
- {file = "mypy-0.901-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:1cd241966a35036f936d4739bd71a1c64e15f02bf7d12bb2815cccfb2993a9de"},
- {file = "mypy-0.901-cp37-cp37m-win_amd64.whl", hash = "sha256:97be0e8ed116f7f79472a49cf06dd45dd806771142401f684d4f13ee652a63c0"},
- {file = "mypy-0.901-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:79beb6741df15395908ecc706b3a593a98804c1d5b5b6bd0c5b03b67c7ac03a0"},
- {file = "mypy-0.901-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:bf347c327c48d963bdef5bf365215d3e98b5fddbe5069fc796cec330e8235a20"},
- {file = "mypy-0.901-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:053b92ebae901fc7954677949049f70133f2f63e3e83dc100225c26d6a46fe95"},
- {file = "mypy-0.901-cp38-cp38-win_amd64.whl", hash = "sha256:f208cc967e566698c4e30a1f65843fc88d8da05a8693bac8b975417e0aee9ced"},
- {file = "mypy-0.901-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c86e3f015bfe7958646825d41c0691c6e5a5cd4015e3409b5c29c18a3c712534"},
- {file = "mypy-0.901-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:e8577d30daf1b7b6582020f539f76e78ee1ed64a0323b28c8e0333c45db9369f"},
- {file = "mypy-0.901-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:5ddd8f4096d5fc2e7d7bb3924ac22758862163ad2c1cdc902c4b85568160e90a"},
- {file = "mypy-0.901-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:4b54518e399c3f4dc53380d4252c83276b2e60623cfc5274076eb8aae57572ac"},
- {file = "mypy-0.901-cp39-cp39-win_amd64.whl", hash = "sha256:7845ad3a31407bfbd64c76d032c16ab546d282930f747023bf07c17b054bebc5"},
- {file = "mypy-0.901-py3-none-any.whl", hash = "sha256:61b10ba18a01d05fc46adbf4f18b0e92178f6b5fd0f45926ffc2a408b5419728"},
- {file = "mypy-0.901.tar.gz", hash = "sha256:18753a8bb9bcf031ff10009852bd48d781798ecbccf45be5449892e6af4e3f9f"},
+ {file = "mypy-0.902-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:3f12705eabdd274b98f676e3e5a89f247ea86dc1af48a2d5a2b080abac4e1243"},
+ {file = "mypy-0.902-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:2f9fedc1f186697fda191e634ac1d02f03d4c260212ccb018fabbb6d4b03eee8"},
+ {file = "mypy-0.902-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:0756529da2dd4d53d26096b7969ce0a47997123261a5432b48cc6848a2cb0bd4"},
+ {file = "mypy-0.902-cp35-cp35m-win_amd64.whl", hash = "sha256:68a098c104ae2b75e946b107ef69dd8398d54cb52ad57580dfb9fc78f7f997f0"},
+ {file = "mypy-0.902-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:cd01c599cf9f897b6b6c6b5d8b182557fb7d99326bcdf5d449a0fbbb4ccee4b9"},
+ {file = "mypy-0.902-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:e89880168c67cf4fde4506b80ee42f1537ad66ad366c101d388b3fd7d7ce2afd"},
+ {file = "mypy-0.902-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:ebe2bc9cb638475f5d39068d2dbe8ae1d605bb8d8d3ff281c695df1670ab3987"},
+ {file = "mypy-0.902-cp36-cp36m-win_amd64.whl", hash = "sha256:f89bfda7f0f66b789792ab64ce0978e4a991a0e4dd6197349d0767b0f1095b21"},
+ {file = "mypy-0.902-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:746e0b0101b8efec34902810047f26a8c80e1efbb4fc554956d848c05ef85d76"},
+ {file = "mypy-0.902-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:0190fb77e93ce971954c9e54ea61de2802065174e5e990c9d4c1d0f54fbeeca2"},
+ {file = "mypy-0.902-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:b5dfcd22c6bab08dfeded8d5b44bdcb68c6f1ab261861e35c470b89074f78a70"},
+ {file = "mypy-0.902-cp37-cp37m-win_amd64.whl", hash = "sha256:b5ba1f0d5f9087e03bf5958c28d421a03a4c1ad260bf81556195dffeccd979c4"},
+ {file = "mypy-0.902-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9ef5355eaaf7a23ab157c21a44c614365238a7bdb3552ec3b80c393697d974e1"},
+ {file = "mypy-0.902-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:517e7528d1be7e187a5db7f0a3e479747307c1b897d9706b1c662014faba3116"},
+ {file = "mypy-0.902-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:fd634bc17b1e2d6ce716f0e43446d0d61cdadb1efcad5c56ca211c22b246ebc8"},
+ {file = "mypy-0.902-cp38-cp38-win_amd64.whl", hash = "sha256:fc4d63da57ef0e8cd4ab45131f3fe5c286ce7dd7f032650d0fbc239c6190e167"},
+ {file = "mypy-0.902-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:353aac2ce41ddeaf7599f1c73fed2b75750bef3b44b6ad12985a991bc002a0da"},
+ {file = "mypy-0.902-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ae94c31bb556ddb2310e4f913b706696ccbd43c62d3331cd3511caef466871d2"},
+ {file = "mypy-0.902-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:8be7bbd091886bde9fcafed8dd089a766fa76eb223135fe5c9e9798f78023a20"},
+ {file = "mypy-0.902-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:4efc67b9b3e2fddbe395700f91d5b8deb5980bfaaccb77b306310bd0b9e002eb"},
+ {file = "mypy-0.902-cp39-cp39-win_amd64.whl", hash = "sha256:9f1d74eeb3f58c7bd3f3f92b8f63cb1678466a55e2c4612bf36909105d0724ab"},
+ {file = "mypy-0.902-py3-none-any.whl", hash = "sha256:a26d0e53e90815c765f91966442775cf03b8a7514a4e960de7b5320208b07269"},
+ {file = "mypy-0.902.tar.gz", hash = "sha256:9236c21194fde5df1b4d8ebc2ef2c1f2a5dc7f18bcbea54274937cae2e20a01c"},
]
mypy-extensions = [
{file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
@@ -2585,10 +2601,18 @@ typer = [
{file = "typer-0.3.2-py3-none-any.whl", hash = "sha256:ba58b920ce851b12a2d790143009fa00ac1d05b3ff3257061ff69dbdfc3d161b"},
{file = "typer-0.3.2.tar.gz", hash = "sha256:5455d750122cff96745b0dec87368f56d023725a7ebc9d2e54dd23dc86816303"},
]
+types-colorama = [
+ {file = "types-colorama-0.4.2.tar.gz", hash = "sha256:ae4f7fcb533e529c182b934423b0c589452ec8b3470430b2ee7baf06cb7f4a8d"},
+ {file = "types_colorama-0.4.2-py2.py3-none-any.whl", hash = "sha256:42bd280fad509c698e1485f9658493076d315d189a5014be843dffee2d264902"},
+]
types-pkg-resources = [
{file = "types-pkg_resources-0.1.3.tar.gz", hash = "sha256:834a9b8d3dbea343562fd99d5d3359a726f6bf9d3733bccd2b4f3096fbab9dae"},
{file = "types_pkg_resources-0.1.3-py2.py3-none-any.whl", hash = "sha256:0cb9972cee992249f93fff1a491bf2dc3ce674e5a1926e27d4f0866f7d9b6d9c"},
]
+types-toml = [
+ {file = "types-toml-0.1.3.tar.gz", hash = "sha256:33ebe67bebaec55a123ecbaa2bd98fe588335d8d8dda2c7ac53502ef5a81a79a"},
+ {file = "types_toml-0.1.3-py2.py3-none-any.whl", hash = "sha256:d4add39a90993173d49ff0b069edd122c66ad4cf5c01082b590e380ca670ee1a"},
+]
typing-extensions = [
{file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"},
{file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"},
diff --git a/pyproject.toml b/pyproject.toml
index 301a54a7..dbd6bd2e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"
@@ -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
diff --git a/scripts/lint.sh b/scripts/lint.sh
index 9af835d0..6db1f8f7 100755
--- a/scripts/lint.sh
+++ b/scripts/lint.sh
@@ -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_*/
diff --git a/setup.cfg b/setup.cfg
index cff281a9..d3a6c814 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/tests/unit/profiles/test_black.py b/tests/unit/profiles/test_black.py
index 0e54e706..7288d478 100644
--- a/tests/unit/profiles/test_black.py
+++ b/tests/unit/profiles/test_black.py
@@ -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,
),
diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py
index bffa7fca..7fe73ab9 100644
--- a/tests/unit/test_api.py
+++ b/tests/unit/test_api.py
@@ -14,7 +14,7 @@ fixed_diff = "+import a\n import b\n-import a\n"
@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
diff --git a/tests/unit/test_deprecated_finders.py b/tests/unit/test_deprecated_finders.py
index bbd43596..3e3be56e 100644
--- a/tests/unit/test_deprecated_finders.py
+++ b/tests/unit/test_deprecated_finders.py
@@ -31,13 +31,13 @@ class TestFindersManager:
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))
@@ -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):
@@ -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
@@ -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
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
index 2cd17aa1..81610557 100644
--- a/tests/unit/test_exceptions.py
+++ b/tests/unit/test_exceptions.py
@@ -11,7 +11,7 @@ class TestISortError:
class TestExistingSyntaxErrors(TestISortError):
def setup_class(self):
- self.instance = exceptions.ExistingSyntaxErrors("file_path")
+ self.instance: exceptions.ExistingSyntaxErrors = exceptions.ExistingSyntaxErrors("file_path")
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -19,7 +19,7 @@ class TestExistingSyntaxErrors(TestISortError):
class TestIntroducedSyntaxErrors(TestISortError):
def setup_class(self):
- self.instance = exceptions.IntroducedSyntaxErrors("file_path")
+ self.instance: exceptions.IntroducedSyntaxErrors = exceptions.IntroducedSyntaxErrors("file_path")
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -27,7 +27,7 @@ class TestIntroducedSyntaxErrors(TestISortError):
class TestFileSkipped(TestISortError):
def setup_class(self):
- self.instance = exceptions.FileSkipped("message", "file_path")
+ self.instance: exceptions.FileSkipped = exceptions.FileSkipped("message", "file_path")
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -36,7 +36,7 @@ class TestFileSkipped(TestISortError):
class TestFileSkipComment(TestISortError):
def setup_class(self):
- self.instance = exceptions.FileSkipComment("file_path")
+ self.instance: exceptions.FileSkipComment = exceptions.FileSkipComment("file_path")
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -44,7 +44,7 @@ class TestFileSkipComment(TestISortError):
class TestFileSkipSetting(TestISortError):
def setup_class(self):
- self.instance = exceptions.FileSkipSetting("file_path")
+ self.instance: exceptions.FileSkipSetting = exceptions.FileSkipSetting("file_path")
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -52,7 +52,7 @@ class TestFileSkipSetting(TestISortError):
class TestProfileDoesNotExist(TestISortError):
def setup_class(self):
- self.instance = exceptions.ProfileDoesNotExist("profile")
+ self.instance: exceptions.ProfileDoesNotExist = exceptions.ProfileDoesNotExist("profile")
def test_variables(self):
assert self.instance.profile == "profile"
@@ -60,7 +60,7 @@ class TestProfileDoesNotExist(TestISortError):
class TestSortingFunctionDoesNotExist(TestISortError):
def setup_class(self):
- self.instance = exceptions.SortingFunctionDoesNotExist("round", ["square", "peg"])
+ self.instance: exceptions.SortingFunctionDoesNotExist = exceptions.SortingFunctionDoesNotExist("round", ["square", "peg"])
def test_variables(self):
assert self.instance.sort_order == "round"
@@ -69,7 +69,7 @@ class TestSortingFunctionDoesNotExist(TestISortError):
class TestLiteralParsingFailure(TestISortError):
def setup_class(self):
- self.instance = exceptions.LiteralParsingFailure("x = [", SyntaxError)
+ self.instance: exceptions.LiteralParsingFailure = exceptions.LiteralParsingFailure("x = [", SyntaxError)
def test_variables(self):
assert self.instance.code == "x = ["
@@ -78,7 +78,7 @@ class TestLiteralParsingFailure(TestISortError):
class TestLiteralSortTypeMismatch(TestISortError):
def setup_class(self):
- self.instance = exceptions.LiteralSortTypeMismatch(tuple, list)
+ self.instance: exceptions.LiteralSortTypeMismatch = exceptions.LiteralSortTypeMismatch(tuple, list)
def test_variables(self):
assert self.instance.kind == tuple
@@ -87,7 +87,7 @@ class TestLiteralSortTypeMismatch(TestISortError):
class TestAssignmentsFormatMismatch(TestISortError):
def setup_class(self):
- self.instance = exceptions.AssignmentsFormatMismatch("print x")
+ self.instance: exceptions.AssignmentsFormatMismatch = exceptions.AssignmentsFormatMismatch("print x")
def test_variables(self):
assert self.instance.code == "print x"
@@ -95,7 +95,7 @@ class TestAssignmentsFormatMismatch(TestISortError):
class TestUnsupportedSettings(TestISortError):
def setup_class(self):
- self.instance = exceptions.UnsupportedSettings({"apply": {"value": "true", "source": "/"}})
+ self.instance: exceptions.UnsupportedSettings = exceptions.UnsupportedSettings({"apply": {"value": "true", "source": "/"}})
def test_variables(self):
assert self.instance.unsupported_settings == {"apply": {"value": "true", "source": "/"}}
@@ -103,7 +103,7 @@ class TestUnsupportedSettings(TestISortError):
class TestUnsupportedEncoding(TestISortError):
def setup_class(self):
- self.instance = exceptions.UnsupportedEncoding("file.py")
+ self.instance: exceptions.UnsupportedEncoding = exceptions.UnsupportedEncoding("file.py")
def test_variables(self):
assert self.instance.filename == "file.py"
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py
index c90f40d2..63a59f9a 100644
--- a/tests/unit/test_isort.py
+++ b/tests/unit/test_isort.py
@@ -9,18 +9,24 @@ import subprocess
import sys
from io import StringIO
from tempfile import NamedTemporaryFile
-from typing import Any, Dict, Iterator, List, Set, Tuple
+from typing import Any, Dict, Iterator, List, Set, Tuple, TYPE_CHECKING
import py
import pytest
import toml
import isort
from isort import api, sections, files
-from isort.settings import WrapModes, Config
+from isort.settings import Config
+
from isort.utils import exists_case_sensitive
from isort.exceptions import FileSkipped, ExistingSyntaxErrors
from .utils import as_stream, UnreadableStream
+if TYPE_CHECKING:
+ WrapModes: Any
+else:
+ from isort.wrap_modes import WrapModes
+
TEST_DEFAULT_CONFIG = """
[*.{py,pyi}]
max_line_length = 120
@@ -225,7 +231,10 @@ def test_line_length() -> None:
)
with pytest.raises(ValueError):
test_output = isort.code(code=REALLY_LONG_IMPORT, line_length=80, wrap_length=99)
- test_output = isort.code(REALLY_LONG_IMPORT, line_length=100, wrap_length=99) == test_input
+ assert isort.code(REALLY_LONG_IMPORT, line_length=100, wrap_length=99) == (
+"""from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12,
+ lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22)
+""")
# Test Case described in issue #1015
test_output = isort.code(
@@ -1271,46 +1280,44 @@ import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
"""
- test_output = (
- isort.code(code=test_input, force_sort_within_sections=True, length_sort=True) == test_input
- )
+ assert isort.code(code=test_input, force_sort_within_sections=True, length_sort=True) == test_input
def test_titled_imports() -> None:
"""Tests setting custom titled/commented import sections."""
- # test_input = (
- # "import sys\n"
- # "import unicodedata\n"
- # "import statistics\n"
- # "import os\n"
- # "import myproject.test\n"
- # "import django.settings"
- # )
- # test_output = isort.code(
- # code=test_input,
- # known_first_party=["myproject"],
- # import_heading_stdlib="Standard Library",
- # import_heading_firstparty="My Stuff",
- # )
- # assert test_output == (
- # "# Standard Library\n"
- # "import os\n"
- # "import statistics\n"
- # "import sys\n"
- # "import unicodedata\n"
- # "\n"
- # "import django.settings\n"
- # "\n"
- # "# My Stuff\n"
- # "import myproject.test\n"
- # )
- # test_second_run = isort.code(
- # code=test_output,
- # known_first_party=["myproject"],
- # import_heading_stdlib="Standard Library",
- # import_heading_firstparty="My Stuff",
- # )
- # assert test_second_run == test_output
+ test_input = (
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "import django.settings"
+ )
+ test_output = isort.code(
+ code=test_input,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
+ )
+ assert test_output == (
+ "# Standard Library\n"
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "# My Stuff\n"
+ "import myproject.test\n"
+ )
+ test_second_run = isort.code(
+ code=test_output,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
+ )
+ assert test_second_run == test_output
test_input_lines_down = (
"# comment 1\n"
@@ -1420,9 +1427,9 @@ while True print 'Hello world'
)
# ensure atomic works with streams
- test_input = as_stream("from b import d, c\nfrom a import f, e\n")
+ test_stream_input = as_stream("from b import d, c\nfrom a import f, e\n")
test_output = UnreadableStream()
- isort.stream(test_input, test_output, atomic=True)
+ isort.stream(test_stream_input, test_output, atomic=True)
test_output.seek(0)
assert test_output.read() == "from a import e, f\nfrom b import c, d\n"
diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py
index 207f19dc..e7697643 100644
--- a/tests/unit/test_main.py
+++ b/tests/unit/test_main.py
@@ -12,10 +12,14 @@ from isort import main
from isort._version import __version__
from isort.exceptions import InvalidSettingsPath
from isort.settings import DEFAULT_CONFIG, Config
-from isort.wrap_modes import WrapModes
from .utils import as_stream
from io import BytesIO, TextIOWrapper
+from typing import TYPE_CHECKING, Any
+if TYPE_CHECKING:
+ WrapModes: Any
+else:
+ from isort.wrap_modes import WrapModes
@given(
file_name=st.text(),
@@ -37,15 +41,15 @@ def test_fuzz_sort_imports(file_name, config, check, ask_to_apply, write_to_stdo
def test_sort_imports(tmpdir):
tmp_file = tmpdir.join("file.py")
tmp_file.write("import os, sys\n")
- assert main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted
+ assert main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
main.sort_imports(str(tmp_file), DEFAULT_CONFIG)
- assert not main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted
+ assert not main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
skip_config = Config(skip=["file.py"])
- assert main.sort_imports(
+ assert main.sort_imports( # type: ignore
str(tmp_file), config=skip_config, check=True, disregard_skip=False
- ).skipped
- assert main.sort_imports(str(tmp_file), config=skip_config, disregard_skip=False).skipped
+ ).skippedg
+ assert main.sort_imports(str(tmp_file), config=skip_config, disregard_skip=False).skipped # type: ignore
def test_sort_imports_error_handling(tmpdir, mocker, capsys):
@@ -53,7 +57,7 @@ def test_sort_imports_error_handling(tmpdir, mocker, capsys):
tmp_file.write("import os, sys\n")
mocker.patch("isort.core.process").side_effect = IndexError("Example unhandled exception")
with pytest.raises(IndexError):
- main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted
+ main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
out, error = capsys.readouterr()
assert "Unrecoverable exception thrown when parsing" in error
@@ -345,7 +349,7 @@ import b
def test_isort_command():
"""Ensure ISortCommand got registered, otherwise setuptools error must have occurred"""
- assert main.ISortCommand
+ assert main.ISortCommand # type: ignore
def test_isort_filename_overrides(tmpdir, capsys):
@@ -1060,7 +1064,7 @@ def test_identify_imports_main(tmpdir, capsys):
len(out.split("\n")) == 2
-def test_gitignore(capsys: pytest.CaptureFixture, tmpdir: py.path.local):
+def test_gitignore(capsys, tmpdir: py.path.local):
import_content = """
import b
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py
index ccd3da22..a7933005 100644
--- a/tests/unit/test_regressions.py
+++ b/tests/unit/test_regressions.py
@@ -233,7 +233,7 @@ def test_ensure_sre_parse_is_identified_as_stdlib_issue_1304():
"""Ensure sre_parse is idenified as STDLIB.
See: https://github.com/pycqa/isort/issues/1304.
"""
- assert isort.place_module("sre_parse") == isort.place_module("sre") == isort.settings.STDLIB
+ assert isort.place_module("sre_parse") == isort.place_module("sre") == isort.settings.STDLIB # type: ignore
def test_add_imports_shouldnt_move_lower_comments_issue_1300():
diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py
index 6ef8f70e..ad0f3ae4 100644
--- a/tests/unit/test_settings.py
+++ b/tests/unit/test_settings.py
@@ -93,11 +93,11 @@ class TestConfig:
assert Config(src_paths=src_paths * 2).src_paths == tuple(src_full_paths)
def test_deprecated_multi_line_output(self):
- assert Config(multi_line_output=6).multi_line_output == WrapModes.VERTICAL_GRID_GROUPED
+ assert Config(multi_line_output=6).multi_line_output == WrapModes.VERTICAL_GRID_GROUPED # type: ignore
def test_as_list():
- assert settings._as_list([" one "]) == ["one"]
+ assert settings._as_list([" one "]) == ["one"] # type: ignore
assert settings._as_list("one,two") == ["one", "two"]