-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Use ruff format #12478
base: main
Are you sure you want to change the base?
Use ruff format #12478
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,8 @@ def sanitise_header(h: Union[Header, str]) -> str: | |
key = json_name(field) | ||
if multi: | ||
value: Union[str, List[str]] = [ | ||
sanitise_header(v) for v in msg.get_all(field) # type: ignore | ||
sanitise_header(v) | ||
for v in msg.get_all(field) # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be a semantic change. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mypy is happy with it, so it should be fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems this is an implementation based semantic (i.e. no standard), for MyPy you should be getting a consistent behavior on Python 3.8+ (but potentially not if you were to run it on 3.7, which Pip's CI doesn't do): python/mypy#6648 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may have misunderstood my comment (or I may have misunderstood your reply). From PEP 484, "The I know I'm being very pedantic here, but I'm bothered by the general idea that ruff is failing to reformat in a way that's semantically identical. The case in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, PEP 484 states the behaviour. But I agree that there's a lot of typing behaviour that's highly dependent on the type checker you use. I have my issues with that, but they aren't relevant here. What is relevant is that ruff shouldn't be making changes it can't be 100% certain are semantically neutral. Please understand, I'm not complaining about ruff here - I'm a huge fan of it. But the formatting capability is relatively new, and I'm not sure I want pip to be an early adopter if there are still issues like this that need to be discussed and resolved (potentially between the formatter and type checker communities - expression-based type ignores may well be a far better resolution, so ruff may be making the right call here). |
||
] | ||
else: | ||
value = sanitise_header(msg.get(field)) # type: ignore | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ def test_completion_alone(autocomplete_script: PipTestEnvironment) -> None: | |
assert ( | ||
"ERROR: You must pass --bash or --fish or --powershell or --zsh" | ||
in result.stderr | ||
), ("completion alone failed -- " + result.stderr) | ||
), "completion alone failed -- " + result.stderr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I prefer black's approach of leaving the parentheses alone here. But I guess the whole point of using an automated formatter is that I'm supposed to not have opinions like that 🙄 |
||
|
||
|
||
def test_completion_for_un_snippet(autocomplete: DoAutocomplete) -> None: | ||
|
@@ -251,10 +251,7 @@ def test_completion_files_after_option( | |
), "autocomplete function could not complete <dir> after options in command" | ||
assert not any( | ||
out in res.stdout for out in (os.path.join("REPLAY", ""), "README.txt") | ||
), ( | ||
"autocomplete function completed <file> or <dir> that " | ||
"should not be completed" | ||
) | ||
), "autocomplete function completed <file> or <dir> that should not be completed" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and even more so here. I much prefer the split and parenthesised version. But whatever, I guess. |
||
if sys.platform != "win32": | ||
return | ||
assert ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,9 +237,12 @@ def test_user_modification(self) -> None: | |
|
||
# get the path to user config file | ||
assert mymock.call_count == 1 | ||
assert mymock.call_args[0][0] == ( | ||
# Use new config file | ||
get_configuration_files()[kinds.USER][1] | ||
assert ( | ||
mymock.call_args[0][0] | ||
== ( | ||
# Use new config file | ||
get_configuration_files()[kinds.USER][1] | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is definitely worse than the black choice. |
||
) | ||
|
||
def test_global_modification(self) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,8 +249,7 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None: | |
# Create directory without read permission | ||
subdir_path = tmpdir / "subdir" | ||
subdir_path.mkdir() | ||
path = str(subdir_path) | ||
os.chmod(path, stat.S_IWRITE) | ||
os.chmod(subdir_path, stat.S_IWRITE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did ruff do this, or was it a manual change? I'm very concerned if this was a ruff change. If it was manual, it's unrelated to this PR, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Manual change indeed. I did it in a separate commit. I detected it because ruff split it in 3 lines which revealed that the # type: ignore was addressing two separate typing issues. So thanks ruff in this case. |
||
|
||
mock_func = Mock() | ||
|
||
|
@@ -264,7 +263,9 @@ def test_rmtree_errorhandler_reraises_error(tmpdir: Path) -> None: | |
# Tuple[None, None, None]]"; expected "Tuple[Type[BaseException], | ||
# BaseException, TracebackType]" | ||
rmtree_errorhandler( | ||
mock_func, path, sys.exc_info() # type: ignore[arg-type] | ||
mock_func, | ||
subdir_path, | ||
sys.exc_info(), # type: ignore[arg-type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I'm not convinced that this doesn't change what's affected by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, the correct reformatting here has to be
This seems to me like a straight bug in ruff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There appears to be a related discussion on ruff side here: astral-sh/ruff#8286 (comment) But no specific issue open on ruff side that I can find which exactly matches your concern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a note about this case to that issue. |
||
) | ||
|
||
mock_func.assert_not_called() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,13 +105,8 @@ def update_version_file(version: str, filepath: str) -> None: | |
|
||
|
||
def create_git_tag(session: Session, tag_name: str, *, message: str) -> None: | ||
session.run( | ||
# fmt: off | ||
"git", "tag", "-m", message, tag_name, | ||
# fmt: on | ||
external=True, | ||
silent=True, | ||
) | ||
cmd = ["git", "tag", "-m", message, tag_name] | ||
session.run(*cmd, external=True, silent=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Manual change, unrelated to ruff? I can accept that the changed version is better, but IMO we shouldn't be mixing changes to the automation and manual reformatting in the one PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I should have done that in another commit. |
||
|
||
|
||
def get_next_development_version(version: str) -> str: | ||
|
@@ -173,12 +168,17 @@ def isolated_temporary_checkout( | |
git_checkout_dir = tmp_dir / f"pip-build-{target_ref}" | ||
nox_session.run( | ||
# fmt: off | ||
"git", "clone", | ||
"--depth", "1", | ||
"--config", "core.autocrlf=false", | ||
"--branch", str(target_ref), | ||
"git", | ||
"clone", | ||
"--depth", | ||
"1", | ||
"--config", | ||
"core.autocrlf=false", | ||
"--branch", | ||
str(target_ref), | ||
"--", | ||
".", str(git_checkout_dir), | ||
".", | ||
str(git_checkout_dir), | ||
# fmt: on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like ruff is flat-out ignoring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is Ruff needing the comments at statement level. See https://docs.astral.sh/ruff/formatter/#format-suppression which says instead of: [
# fmt: off
'1',
# fmt: on
'2',
] Do: # fmt: off
[
'1',
'2',
]
# fmt: on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood. I still think it's a problem with ruff, though. At the absolute minimum it should warn if it's ignoring formatting directives. (Specifically if it's ignoring directives that other formatters like black would respect). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They have an open issue on warning, I'm sure sure supportive feedback would be welcome: astral-sh/ruff#6611 |
||
external=True, | ||
silent=True, | ||
|
@@ -191,9 +191,13 @@ def get_git_untracked_files() -> Iterator[str]: | |
"""List all local file paths that aren't tracked by Git.""" | ||
git_ls_files_cmd = ( | ||
# fmt: off | ||
"git", "ls-files", | ||
"--ignored", "--exclude-standard", | ||
"--others", "--", ".", | ||
"git", | ||
"ls-files", | ||
"--ignored", | ||
"--exclude-standard", | ||
"--others", | ||
"--", | ||
".", | ||
# fmt: on | ||
) | ||
# session.run doesn't seem to return any output: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bothers me because it's in a
# fmt: off
block. Does ruff not support that directive?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruff is more limited in where it supports supression statements: astral-sh/ruff#6338
I suspect this is a location where it does not support them, ruff has been considering adding a warning for this case: astral-sh/ruff#6611