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 2 #2329

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

matthewhughes934
Copy link
Contributor

Second round of updates, split out to keep PRs reasonable size

  • Drop py dependency

    This package is in maintenance only mode and only had two uses. Replace
    their use with the tmp_path fixture as suggested in the docs[1]

    Link: https://docs.pytest.org/en/8.3.x/reference/reference.html#tmpdir [1]

  • Update pytest

    There was one new error:

      TypeError: exceptions must be derived from Warning, not <class 'NoneType'>
    

    Fix this following the docs[1]

    Link: https://docs.pytest.org/en/8.3.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests [1]

  • Update black

  • Update flake8

    This required fixes an error in the config (I also updated the relevant
    link, the old one would 404):

      ValueError: Error code '#' supplied to 'extend-ignore' option does not match '^[A-Z]{1,3}[0-9]{0,3}$'
    

    And some errors in the code:

      isort/literal.py:59:8: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
      tests/unit/test_isort.py:13:1: F401 'typing.Dict' imported but unused
    

    The second test conflicted with mypy, since Dict was only used in
    commented annotations, to make them both happy move one of these
    annotations out of a comment (in the future we should probably move all
    such annotations out of comments)

  • Update hypothesis

    This required addressing some errors from mypy:

      tests/integration/test_setting_combinations.py:20: error: "SearchStrategy" expects no type arguments, but 1 given  [type-arg]
      tests/integration/test_hypothesmith.py:36: error: "SearchStrategy" expects no type arguments, but 1 given  [type-arg]
    

This package is in maintenance only mode and only had two uses. Replace
their use with the `tmp_path` fixture as suggested in the docs[1]

Link: https://docs.pytest.org/en/8.3.x/reference/reference.html#tmpdir [1]
There was one new error:

    TypeError: exceptions must be derived from Warning, not <class 'NoneType'>

Fix this following the docs[1]

Link: https://docs.pytest.org/en/8.3.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests [1]
This required fixes an error in the config (I also updated the relevant
link, the old one would 404):

    ValueError: Error code '#' supplied to 'extend-ignore' option does not match '^[A-Z]{1,3}[0-9]{0,3}$'

And some errors in the code:

    isort/literal.py:59:8: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
    tests/unit/test_isort.py:13:1: F401 'typing.Dict' imported but unused

The second test conflicted with `mypy`, since `Dict` was only used in
commented annotations, to make them both happy move one of these
annotations out of a comment (in the future we should probably move all
such annotations out of comments)
This required addressing some errors from `mypy`:

    tests/integration/test_setting_combinations.py:20: error: "SearchStrategy" expects no type arguments, but 1 given  [type-arg]
    tests/integration/test_hypothesmith.py:36: error: "SearchStrategy" expects no type arguments, but 1 given  [type-arg]
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.12%. Comparing base (78c30dc) to head (4efc999).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2329   +/-   ##
=======================================
  Coverage   99.12%   99.12%           
=======================================
  Files          39       39           
  Lines        3095     3095           
  Branches      787      787           
=======================================
  Hits         3068     3068           
  Misses         15       15           
  Partials       12       12           

Copy link
Member

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

The changes due to py should probably be refactored a bit, see my comments.

This also supersedes #2235 and closes #2235

python_file.write(import_content)
tmpdir.join("no_imports.py").write("...")
subprocess.run(["git", "init", str(tmp_path)])
python_file = tmp_path.joinpath("has_imports.py")
Copy link
Member

Choose a reason for hiding this comment

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

Could you use / here as well as other places? I believe that is more idiomatic?


out, error = main_check(
[str(git_project0), "--skip-gitignore", "--filter-files", "--check"]
)

should_check = ["/git_project0/has_imports.py"]

assert all(f"{str(tmpdir)}{file}" in error for file in should_check)
assert all(f"{str(tmp_path)}{file}" in error for file in should_check)
Copy link
Member

Choose a reason for hiding this comment

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

Using both str and f" shouldn't be necessary for Path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using both str and f" shouldn't be necessary for Path

what do you think about making this a separate change: I see there are several points in this file (including parts not touched by this change) that could do with the same update? I'm happy to include it in this patch, but my main goal was to just get things working, without changing things too much

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to exclude the py change and do that together with the changes in a separate PR?

If not, let's at least make sure the code we're touching now in this diff is correct and worry about the rest later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If not, let's at least make sure the code we're touching now in this diff is correct and worry about the rest later.

👍 830eca7

@@ -1629,13 +1629,13 @@ def test_multiline_import() -> None:
assert isort.code(test_input) == ("from pkg import more_stuff, other_suff, stuff\n")

# test again with a custom configuration
custom_configuration = {
custom_configuration: Dict[str, Any] = {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use dict[str, Any]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you use dict[str, Any]?

yep, now that we don't support Python 3.8 that will work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done with cbd07e0

@matthewhughes934
Copy link
Contributor Author

I've pushed some fixup commits, so let me know just before merge and I'll rebase to squash them back in to the correct commits

@matthewhughes934
Copy link
Contributor Author

matthewhughes934 commented Jan 10, 2025

Lint is unhappy

tests/unit/test_isort.py:13:1: F401 'typing.Dict' imported but unused

becuase that file uses type comments like type: Dict[str, Any], so that needs to be imported when TYPE_CHECKING, or that file could be updated to replace those comments with type annotations (preferable, but happy to have that as a separate change)

EDIT: actually, it complains even when imported only when TYPE_CHECKING

EDIT EDIT: 4efc999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants