-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fixed inability to pass total_tokens as a keyword argument on trio #666
Conversation
def __init__( | ||
self, *args: Any, original: trio.CapacityLimiter | None = None | ||
self, | ||
total_tokens: float | None = None, | ||
*, | ||
original: trio.CapacityLimiter | None = None, | ||
) -> None: | ||
self.__original = original or trio.CapacityLimiter(*args) | ||
if original is not None: | ||
self.__original = original | ||
else: | ||
assert total_tokens is not None | ||
self.__original = trio.CapacityLimiter(total_tokens) |
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 you want, you could tell the type checker about this:
+ @overload
+ def __init__(self, total_tokens: float) -> None:
+ ...
+
+ @overload
+ def __init__(self, *, original: trio.CapacityLimiter) -> None:
+ ...
+
def __init__(
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'm not sure there's much point, as this is an internal thing. And wouldn't I also have to do the same with __new__()
?
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'm not sure there's much point, as this is an internal thing.
agreed.
And wouldn't I also have to do the same with
__new__()
?
no, because in a call CapacityLimiter(...)
the type checker must ensure that the arguments are valid to pass to both __new__
and __init__
. if at least one of the two has the overloads (i.e. has the extra strictness), the type checker will reject invalid calls like CapacityLimiter(1, original=trio.CapacityLimiter(1))
. they do not both need to specify the full strictness of the overload.
tested: with both Mypy and pyright, the call CapacityLimiter(1, original=trio.CapacityLimiter(1))
is rejected when __init__
is overloaded, no matter whether the overload is copied to __new__
too or not.
Thanks for the review. |
Fixes #515.