Skip to content

Commit

Permalink
Update mypy to v1+
Browse files Browse the repository at this point in the history
This includes removing some now unused ignores, and fixing some new
errors:

    isort/sorting.py:120: error: Unused "type: ignore" comment  [unused-ignore]
    isort/settings.py:869: error: Unused "type: ignore" comment  [unused-ignore]
    isort/literal.py:89: error: Unused "type: ignore" comment  [unused-ignore]
    isort/deprecated/finders.py:32: error: Incompatible types in assignment (expression has type "None", variable has type "Callable[[PathLike[Any], Optional[Any], bool, bool], Dict[str, Union[Requirement, UnparsedRequirement]]]")  [assignment]
    isort/api.py:196: error: No overload variant of "compile" matches argument types "str", "str", "str", "int", "int"  [call-overload]
    isort/api.py:196: note: Possible overload variants:
    isort/api.py:196: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: Literal[0], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> CodeType
    isort/api.py:196: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, *, dont_inherit: bool = ..., optimize: int = ..., _feature_version: int = ...) -> CodeType
    isort/api.py:196: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: Literal[1024], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> AST
    isort/api.py:196: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: int, dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> Any
    isort/api.py:223: error: No overload variant of "compile" matches argument types "str", "str", "str", "int", "int"  [call-overload]
    isort/api.py:223: note: Possible overload variants:
    isort/api.py:223: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: Literal[0], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> CodeType
    isort/api.py:223: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, *, dont_inherit: bool = ..., optimize: int = ..., _feature_version: int = ...) -> CodeType
    isort/api.py:223: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: Literal[1024], dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> AST
    isort/api.py:223: note:     def compile(source: Union[str, Buffer, Module, Expression, Interactive], filename: Union[str, Buffer, _PathLike[Any]], mode: str, flags: int, dont_inherit: bool = ..., optimize: int = ..., *, _feature_version: int = ...) -> Any
    tests/integration/test_setting_combinations.py:64: error: Unused "type: ignore" comment  [unused-ignore]
    tests/unit/test_isort.py:5550: error: Signature of "seek" incompatible with supertype "TextIOWrapper"  [override]
    tests/unit/test_isort.py:5550: note:      Superclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, int, int = ..., /) -> int
    tests/unit/test_isort.py:5550: note:      Subclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, position: Any) -> Any
    tests/unit/test_isort.py:5550: error: Signature of "seek" incompatible with supertype "IOBase"  [override]
    tests/unit/test_isort.py:5550: note:      Superclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, int, int = ..., /) -> int
    tests/unit/test_isort.py:5550: note:      Subclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, position: Any) -> Any
    tests/unit/test_isort.py:5550: error: Signature of "seek" incompatible with supertype "IO"  [override]
    tests/unit/test_isort.py:5550: note:      Superclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, int, int = ..., /) -> int
    tests/unit/test_isort.py:5550: note:      Subclass:
    tests/unit/test_isort.py:5550: note:          def seek(self, position: Any) -> Any
    tests/integration/test_hypothesmith.py:69: error: Unused "type: ignore" comment  [unused-ignore]
    Found 11 errors in 8 files (checked 88 source files)
  • Loading branch information
matthewhughes934 committed Jan 20, 2025
1 parent b575abb commit 373ca64
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 49 deletions.
4 changes: 2 additions & 2 deletions isort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def sort_stream(
if config.atomic:
try:
file_content = input_stream.read()
compile(file_content, content_source, "exec", 0, 1)
compile(file_content, content_source, "exec", flags=0, dont_inherit=True)
except SyntaxError:
if extension not in CYTHON_EXTENSIONS:
raise ExistingSyntaxErrors(content_source)
Expand All @@ -220,7 +220,7 @@ def sort_stream(
if config.atomic:
_internal_output.seek(0)
try:
compile(_internal_output.read(), content_source, "exec", 0, 1)
compile(_internal_output.read(), content_source, "exec", flags=0, dont_inherit=True)
_internal_output.seek(0)
except SyntaxError: # pragma: no cover
if extension not in CYTHON_EXTENSIONS:
Expand Down
2 changes: 1 addition & 1 deletion isort/deprecated/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pip_api import parse_requirements # type: ignore

except ImportError:
parse_requirements = None
parse_requirements = None # type: ignore[assignment]


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion isort/literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def wrap(

@register_type("dict", dict)
def _dict(value: Dict[Any, Any], printer: ISortPrettyPrinter) -> str:
return printer.pformat(dict(sorted(value.items(), key=lambda item: item[1]))) # type: ignore
return printer.pformat(dict(sorted(value.items(), key=lambda item: item[1])))


@register_type("list", list)
Expand Down
3 changes: 2 additions & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,8 @@ def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any
and config_key.endswith("}")
and extension
in map(
lambda text: text.strip(), config_key[len("*.{") : -1].split(",") # type: ignore # noqa
lambda text: text.strip(),
config_key[len("*.{") : -1].split(","), # noqa
)
):
settings.update(config.items(config_key))
Expand Down
2 changes: 1 addition & 1 deletion isort/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def naturally(
else:

def key_callback(text: str) -> List[Any]:
return _natural_keys(key(text)) # type: ignore
return _natural_keys(key(text))

return sorted(to_sort, key=key_callback, reverse=reverse)

Expand Down
87 changes: 48 additions & 39 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ httpx = ">=0.13.3"
hypothesis = ">=6.10.1"
hypothesmith = ">=0.1.3"
libcst = ">=0.3.18"
mypy = ">=0.902,<1.0.0"
mypy = ">=1.14.1"
mypy-extensions = ">=0.4.3"
pep8-naming = ">=0.8.2"
pip = ">=21.1.1"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_hypothesmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def configs(**force_strategies: st.SearchStrategy) -> st.SearchStrategy:
"py_version": st.sampled_from(("auto",) + isort.settings.VALID_PY_TARGETS),
}
kwargs = {**inferred_kwargs, **specific, **force_strategies}
return st.fixed_dictionaries({}, optional=kwargs).map(_as_config) # type: ignore
return st.fixed_dictionaries({}, optional=kwargs).map(_as_config)


st.register_type_strategy(isort.Config, configs())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_setting_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def configs() -> st.SearchStrategy:
"py_version": st.sampled_from(("auto",) + isort.settings.VALID_PY_TARGETS),
}
kwargs = {**inferred_kwargs, **specific}
return st.fixed_dictionaries({}, optional=kwargs).map(_as_config) # type:ignore
return st.fixed_dictionaries({}, optional=kwargs).map(_as_config)


st.register_type_strategy(isort.Config, configs())
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5551,7 +5551,7 @@ def test_find_imports_in_stream() -> None:
"""Ensure that find_imports_in_stream can work with nonseekable streams like STDOUT"""

class NonSeekableTestStream(StringIO):
def seek(self, position):
def seek(self, offset: int, whence: int = os.SEEK_SET, /) -> int:
raise OSError("Stream is not seekable")

def seekable(self):
Expand Down

0 comments on commit 373ca64

Please sign in to comment.