-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[pyupgrade
] Add resource.error
as deprecated alias of OSError
(UP024
)
#17933
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
Conversation
|
6bfdc7b
to
f1da146
Compare
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.
Nice, this makes sense to me! For a test, you'll want to add a new UP024 test fixture like this:
class SocketError(Exception): | |
pass | |
try: | |
raise SocketError() | |
except SocketError: | |
pass |
It looks like UP024_5.py
is the next available name (I linked to 3 since it's a bit more minimal of an example than 4).
And then you can add a new test_case
here:
ruff/crates/ruff_linter/src/rules/pyupgrade/mod.rs
Lines 48 to 53 in ec2fdad
#[test_case(Rule::OSErrorAlias, Path::new("UP024_0.py"))] | |
#[test_case(Rule::OSErrorAlias, Path::new("UP024_1.py"))] | |
#[test_case(Rule::OSErrorAlias, Path::new("UP024_2.py"))] | |
#[test_case(Rule::OSErrorAlias, Path::new("UP024_3.py"))] | |
#[test_case(Rule::OSErrorAlias, Path::new("UP024_4.py"))] | |
#[test_case(Rule::OpenAlias, Path::new("UP020.py"))] |
That should be all you need to generate new snapshots, which you can update with cargo-insta. The prerequisites section in the CONTRIBUTING.md file has some links for setting that up, if you need it. I'm happy to help if you run into any issues! I think this is good to go once we have a simple test case :)
f1da146
to
0bffb6b
Compare
I chose to modify the existing test instead:
Unfortunately, the whole toolchain eats too much disk space, I cannot run tests on my computer. I'll try on a machine with more disk space next week. |
0bffb6b
to
3f722c4
Compare
Thanks for adding the tests. Let me know if you want me to update the snapshots for you. |
3f722c4
to
6f50ce7
Compare
Snapshots updated. |
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.
Thanks!
pyupgrade
] Add resource.error
as deprecated alias of OSError
(UP024
)
…`UP024`) (astral-sh#17933) ## Summary Partially addresses astral-sh#17935. [`resource.error`](https://docs.python.org/3/library/resource.html#resource.error) is a deprecated alias of [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError). > _Changed in version 3.3:_ Following [**PEP 3151**](https://peps.python.org/pep-3151/), this class was made an alias of [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError). Add it to the list of `OSError` aliases found by [os-error-alias (UP024)](https://docs.astral.sh/ruff/rules/os-error-alias/#os-error-alias-up024). ## Test Plan Sorry, I usually don't program in Rust. Could you at least point me to the test I would need to modify?
Summary
Partially addresses #17935.
resource.error
is a deprecated alias ofOSError
.Add it to the list of
OSError
aliases found by os-error-alias (UP024).Test Plan
Sorry, I usually don't program in Rust. Could you at least point me to the test I would need to modify?