-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
Changes from all commits
4af786b
c6a32f2
fab4a08
c31e0a6
bccd2ed
5cbcb46
6891b40
2ce22e7
3e74044
e275513
32c4037
dc1153e
641fa56
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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
Callable, | ||
Iterator, | ||
Literal, | ||
Optional, | ||
TypeVar, | ||
cast, | ||
) | ||
|
@@ -245,9 +244,9 @@ class CKeys(enum.IntEnum): | |
# operation and start a new one. | ||
@attr.s(slots=True, eq=False) | ||
class AFDWaiters: | ||
read_task: Optional[_core.Task] = attr.ib(default=None) | ||
write_task: Optional[_core.Task] = attr.ib(default=None) | ||
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 commentThe 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 commentThe 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 |
||
|
||
|
||
# We also need to bundle up all the info for a single op into a standalone | ||
|
@@ -585,9 +584,9 @@ def process_events(self, received: EventResult) -> None: | |
pass | ||
else: | ||
exc = _core.TrioInternalError( | ||
"Failed to cancel overlapped I/O in {} and didn't " | ||
f"Failed to cancel overlapped I/O in {waiter.name} and didn't " | ||
"receive the completion either. Did you forget to " | ||
"call register_with_iocp()?".format(waiter.name) | ||
"call register_with_iocp()?" | ||
) | ||
# Raising this out of handle_io ensures that | ||
# the user will see our message even if some | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,28 +135,26 @@ def _return_value_looks_like_wrong_library(value: object) -> bool: | |
|
||
raise TypeError( | ||
"Trio was expecting an async function, but instead it got " | ||
"a coroutine object {async_fn!r}\n" | ||
f"a coroutine object {async_fn!r}\n" | ||
"\n" | ||
"Probably you did something like:\n" | ||
"\n" | ||
" 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Same string concat weirdness (see other comment) |
||
"\n" | ||
"Instead, you want (notice the parentheses!):\n" | ||
"\n" | ||
" trio.run({async_fn.__name__}, ...) # correct!\n" | ||
" nursery.start_soon({async_fn.__name__}, ...) # correct!".format( | ||
async_fn=async_fn | ||
) | ||
f" trio.run({async_fn.__name__}, ...) # correct!\n" | ||
f" nursery.start_soon({async_fn.__name__}, ...) # correct!" | ||
) from None | ||
|
||
# Give good error for: nursery.start_soon(future) | ||
if _return_value_looks_like_wrong_library(async_fn): | ||
raise TypeError( | ||
"Trio was expecting an async function, but instead it got " | ||
"{!r} – are you trying to use a library written for " | ||
f"{async_fn!r} – are you trying to use a library written for " | ||
"asyncio/twisted/tornado or similar? That won't work " | ||
"without some sort of compatibility shim.".format(async_fn) | ||
"without some sort of compatibility shim." | ||
) from None | ||
|
||
raise | ||
|
@@ -174,15 +172,15 @@ def _return_value_looks_like_wrong_library(value: object) -> bool: | |
# Give good error for: nursery.start_soon(func_returning_future) | ||
if _return_value_looks_like_wrong_library(coro): | ||
raise TypeError( | ||
"Trio got unexpected {!r} – are you trying to use a " | ||
f"Trio got unexpected {coro!r} – are you trying to use a " | ||
"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 commentThe 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 commentThe 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. |
||
) | ||
|
||
if inspect.isasyncgen(coro): | ||
raise TypeError( | ||
"start_soon expected an async function but got an async " | ||
"generator {!r}".format(coro) | ||
f"generator {coro!r}" | ||
) | ||
|
||
# Give good error for: nursery.start_soon(some_sync_fn) | ||
|
@@ -370,7 +368,7 @@ def __call__(cls, *args: object, **kwargs: object) -> None: | |
f"{cls.__module__}.{cls.__qualname__} has no public constructor" | ||
) | ||
|
||
def _create(cls: t.Type[T], *args: object, **kwargs: object) -> T: | ||
def _create(cls: type[T], *args: object, **kwargs: object) -> T: | ||
return super().__call__(*args, **kwargs) # type: ignore | ||
|
||
|
||
|
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 thefrom __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.