-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid failures due to non-deterministic binding ordering (#10478)
## Summary We're seeing failures in #10470 because `resolve_qualified_import_name` isn't guaranteed to return a specific import if a symbol is accessible in two ways (e.g., you have both `import logging` and `from logging import error` in scope, and you want `logging.error`). This PR breaks up the failing tests such that the imports aren't in the same scope. Closes #10470. ## Test Plan I added a `bindings.reverse()` to `resolve_qualified_import_name` to ensure that the tests pass regardless of the binding order.
- Loading branch information
1 parent
ffd6e79
commit bc9b457
Showing
17 changed files
with
1,001 additions
and
1,120 deletions.
There are no files selected for viewing
15 changes: 9 additions & 6 deletions
15
crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG009.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import logging | ||
def func(): | ||
import logging | ||
|
||
logging.WARN # LOG009 | ||
logging.WARNING # OK | ||
logging.WARN # LOG009 | ||
logging.WARNING # OK | ||
|
||
from logging import WARN, WARNING | ||
|
||
WARN # LOG009 | ||
WARNING # OK | ||
def func(): | ||
from logging import WARN, WARNING | ||
|
||
WARN # LOG009 | ||
WARNING # OK |
35 changes: 26 additions & 9 deletions
35
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP017.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
import datetime | ||
import datetime as dt | ||
from datetime import timezone | ||
from datetime import timezone as tz | ||
def func(): | ||
import datetime | ||
|
||
print(datetime.timezone(-1)) | ||
print(timezone.utc) | ||
print(tz.utc) | ||
print(datetime.timezone(-1)) | ||
|
||
print(datetime.timezone.utc) | ||
print(dt.timezone.utc) | ||
|
||
def func(): | ||
from datetime import timezone | ||
|
||
print(timezone.utc) | ||
|
||
|
||
def func(): | ||
from datetime import timezone as tz | ||
|
||
print(tz.utc) | ||
|
||
|
||
def func(): | ||
import datetime | ||
|
||
print(datetime.timezone.utc) | ||
|
||
|
||
def func(): | ||
import datetime as dt | ||
|
||
print(dt.timezone.utc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# No `typing.Optional` import | ||
|
||
|
||
def f(arg: int = None): # RUF011 | ||
def f(arg: int = None): # RUF013 | ||
pass |
30 changes: 30 additions & 0 deletions
30
crates/ruff_linter/resources/test/fixtures/ruff/RUF013_3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import typing | ||
|
||
|
||
def f(arg: typing.List[str] = None): # RUF013 | ||
pass | ||
|
||
|
||
# Optional | ||
|
||
|
||
def f(arg: typing.Optional[int] = None): | ||
pass | ||
|
||
|
||
# Union | ||
|
||
|
||
def f(arg: typing.Union[int, str, None] = None): | ||
pass | ||
|
||
|
||
def f(arg: typing.Union[int, str] = None): # RUF013 | ||
pass | ||
|
||
|
||
# Literal | ||
|
||
|
||
def f(arg: typing.Literal[1, "foo", True] = None): # RUF013 | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 29 additions & 30 deletions
59
...flake8_logging/snapshots/ruff_linter__rules__flake8_logging__tests__LOG009_LOG009.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_logging/mod.rs | ||
--- | ||
LOG009.py:3:1: LOG009 [*] Use of undocumented `logging.WARN` constant | ||
LOG009.py:4:5: LOG009 [*] Use of undocumented `logging.WARN` constant | ||
| | ||
1 | import logging | ||
2 | | ||
3 | logging.WARN # LOG009 | ||
| ^^^^^^^^^^^^ LOG009 | ||
4 | logging.WARNING # OK | ||
2 | import logging | ||
3 | | ||
4 | logging.WARN # LOG009 | ||
| ^^^^^^^^^^^^ LOG009 | ||
5 | logging.WARNING # OK | ||
| | ||
= help: Replace `logging.WARN` with `logging.WARNING` | ||
|
||
ℹ Safe fix | ||
1 1 | import logging | ||
2 2 | | ||
3 |-logging.WARN # LOG009 | ||
3 |+logging.WARNING # LOG009 | ||
4 4 | logging.WARNING # OK | ||
5 5 | | ||
6 6 | from logging import WARN, WARNING | ||
|
||
LOG009.py:8:1: LOG009 [*] Use of undocumented `logging.WARN` constant | ||
| | ||
6 | from logging import WARN, WARNING | ||
7 | | ||
8 | WARN # LOG009 | ||
| ^^^^ LOG009 | ||
9 | WARNING # OK | ||
| | ||
= help: Replace `logging.WARN` with `logging.WARNING` | ||
|
||
ℹ Safe fix | ||
5 5 | | ||
6 6 | from logging import WARN, WARNING | ||
1 1 | def func(): | ||
2 2 | import logging | ||
3 3 | | ||
4 |- logging.WARN # LOG009 | ||
4 |+ logging.WARNING # LOG009 | ||
5 5 | logging.WARNING # OK | ||
6 6 | | ||
7 7 | | ||
8 |-WARN # LOG009 | ||
8 |+logging.WARNING # LOG009 | ||
9 9 | WARNING # OK | ||
|
||
LOG009.py:11:5: LOG009 [*] Use of undocumented `logging.WARN` constant | ||
| | ||
9 | from logging import WARN, WARNING | ||
10 | | ||
11 | WARN # LOG009 | ||
| ^^^^ LOG009 | ||
12 | WARNING # OK | ||
| | ||
= help: Replace `logging.WARN` with `logging.WARNING` | ||
|
||
ℹ Safe fix | ||
8 8 | def func(): | ||
9 9 | from logging import WARN, WARNING | ||
10 10 | | ||
11 |- WARN # LOG009 | ||
11 |+ WARNING # LOG009 | ||
12 12 | WARNING # OK |
Oops, something went wrong.