Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates round 3 #2334

Merged
merged 2 commits into from
Jan 20, 2025
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 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]
Copy link
Member

Choose a reason for hiding this comment

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

This can be fixed by initialising parse_requirements on line 27 as parse_requirements: types.ModelType | None right? Or does mypy no longer support that pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be fixed by initialising parse_requirements on line 27 as parse_requirements: types.ModelType | None right? Or does mypy no longer support that pattern?

Sorry, what is types.ModelType?

I think the typing would have to be something like (from a glance at /~https://github.com/di/pip-api/blob/21eea42e37b29e18c004a922f8989108a006a203/pip_api/_parse_requirements.py#L484):

parse_requirements: (
    Callable[
        [os.PathLike[str], Optional[Any], bool, bool],
        Dict[str, Union[pip_api.Requirement, pip_api.UnparsedRequirement]],
    ]
    | None
)

but that's a bit tricky, because at this point pip_api isn't imported, so pip_api.UnparsedRequirement is unknown

Copy link
Member

Choose a reason for hiding this comment

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

Ah my bad, didn't read this correctly.

Indeed seems like fixing this is more trouble than it is worth



@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
95 changes: 52 additions & 43 deletions poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ cruft = ">=2.12.0"
example-isort-sorting-plugin = ">=0.1.0"
example-shared-isort-profile = ">=0.1.0"
flake8 = ">=3.8.4"
flake8-bugbear = ">=22.12.6,<23.0.0"
flake8-bugbear = ">=22.12.12"
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
4 changes: 2 additions & 2 deletions tests/unit/test_setuptools_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_isort_command_smoke(src_dir):
command.finalize_options()
try:
command.run()
except BaseException:
except SystemExit:
pass

command.distribution.package_dir = {"": "isort"}
Expand All @@ -27,5 +27,5 @@ def test_isort_command_smoke(src_dir):
command.finalize_options()
try:
command.run()
except BaseException:
except SystemExit:
pass
Loading