-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Enable pyupgrade rule #2809
Enable pyupgrade rule #2809
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2809 +/- ##
=======================================
Coverage 99.16% 99.16%
=======================================
Files 115 115
Lines 17482 17482
Branches 3113 3113
=======================================
Hits 17336 17336
Misses 101 101
Partials 45 45
|
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.
Couple of comments but overall looks good
@@ -201,7 +201,7 @@ class _EpollStatistics: | |||
class EpollIOManager: | |||
_epoll: select.epoll = attr.ib(factory=select.epoll) | |||
# {fd: EpollWaiters} | |||
_registered: DefaultDict[int, EpollWaiters] = attr.ib( | |||
_registered: defaultdict[int, EpollWaiters] = attr.ib( |
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.
Isn't defaultdict
a 3.9+ thing? Why is ruff doing this? Cause the from __future__ import annotations
? or is this a bug.
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.
It’s probably that yes. There’s an option to decide whether to preserve the hints making sense at runtime.
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.
Yes, it decides what's allowed based on both the version you specify and if a future annotations import exists.
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.
There is a setting to make sure runtime typing works, mostly so a specific library can work properly, but in my opinion I agree with ruff's behavior here. Why have outdated versions of the type annotations if we don't have to worry about runtime type annotations?
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.
It's been waffled about a lot in various PR's, without a central decision actually getting taken: #2687
IMHO if we want runtime typing we should have tests for it, and enforce it with linter rules.
current_op: Optional[AFDPollOp] = attr.ib(default=None) | ||
read_task: _core.Task | None = attr.ib(default=None) | ||
write_task: _core.Task | None = attr.ib(default=None) | ||
current_op: AFDPollOp | None = attr.ib(default=None) |
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.
Eh, same as above. I won't make any more comments about 3.9+ features sneaking in.
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.
If we are going to require runtime typing, on 3.8, and that disallowing using |
in type hints, then I vehemently disagree with doing that. This is currently the status quo in a lot of the code base.
trio/_dtls.py
Outdated
SSL.OP_NO_QUERY_MTU | ||
| SSL.OP_NO_RENEGOTIATION # type: ignore[attr-defined] | ||
) | ||
SSL.OP_NO_QUERY_MTU | SSL.OP_NO_RENEGOTIATION # type: ignore[attr-defined] |
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.
Huh, why did ruff change this? I think it was intentionally formatted to showcase which specific attribute wasn't defined.
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.
I saw this and the diff and was a bit confused myself, not sure about this one.
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.
Another one of my PRs hit this and I looked into it further, this change was by black, not ruff.
" trio.run({async_fn.__name__}(...)) # incorrect!\n" | ||
" nursery.start_soon({async_fn.__name__}(...)) # incorrect!\n" | ||
f" trio.run({async_fn.__name__}(...)) # incorrect!\n" | ||
f" nursery.start_soon({async_fn.__name__}(...)) # incorrect!\n" |
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.
Mind checking the commit that these came in with (or the PR more generally) and seeing if there's other stuff like this?
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.
Same string concat weirdness (see other comment)
"library written for asyncio/twisted/tornado or similar? " | ||
"That won't work without some sort of compatibility shim.".format(coro) | ||
"That won't work without some sort of compatibility shim." |
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.
Wow messed up upgrade bugs everywhere. Mind checking the commit/PR that this came in with too?
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.
I don't think it's actually a bug, I think the format call would have worked for it previously because it was applying to the concatenation of all of the strings, since they have parenthesis wrapping them. It definitely looks kind of strange though, and I think using f-strings here makes it much more clear what the idea is than this format call that looks a bit out of place.
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.
imo we can merge this, but Somebody ™️ needs to take a final decision on runtime typing. That affects much more code than this though, so I don't think it should hold up this one.
@@ -201,7 +201,7 @@ class _EpollStatistics: | |||
class EpollIOManager: | |||
_epoll: select.epoll = attr.ib(factory=select.epoll) | |||
# {fd: EpollWaiters} | |||
_registered: DefaultDict[int, EpollWaiters] = attr.ib( | |||
_registered: defaultdict[int, EpollWaiters] = attr.ib( |
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.
It's been waffled about a lot in various PR's, without a central decision actually getting taken: #2687
IMHO if we want runtime typing we should have tests for it, and enforce it with linter rules.
current_op: Optional[AFDPollOp] = attr.ib(default=None) | ||
read_task: _core.Task | None = attr.ib(default=None) | ||
write_task: _core.Task | None = attr.ib(default=None) | ||
current_op: AFDPollOp | None = attr.ib(default=None) |
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.
If we are going to require runtime typing, on 3.8, and that disallowing using |
in type hints, then I vehemently disagree with doing that. This is currently the status quo in a lot of the code base.
You can merge this after fixing B904. |
pre-commit.ci autofix |
This PR enables the pyupgrade ruff rule and fixes all the existing issues that were raised.