-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Please check our new types! #2775
Comments
I ran this against AnyIO and got 7 errors about unused |
Checking against tricycle, it just looks like over-adaptation to
(this is just the start of the output) |
Ah no, that's an incorrect type hint that's getting fixed in #2773 (comment) |
I am running with pyright and it shows this error:
for this code (trio from master as of now): import trio
async def test():
async with trio.Lock():
print("HI")
trio.run(test) |
My first guess is that pyright doesn't support the self-type pattern we use in trio/_sync for async with, added in e97bcb6 If someone could confirm this with a small reproduction and make an issue on pyright's repository, I believe that will be fixed quickly. EDIT: actually, no longer sure cause I couldn't make a simple reproduction of what I thought the bug was. I'll check this out later. |
This is going way over my head. I played around a bit with it and replaced class AsyncContextManagerMixin:
#@enable_ki_protection
async def __aenter__(self: _HasAcquireRelease) -> None:
await self.acquire()
__aenter__ = enable_ki_protection(__aenter__)
#@enable_ki_protection
async def __aexit__(
self: _HasAcquireRelease,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
self.release()
__aexit__ = enable_ki_protection(__aexit__) so essentially I replaced Now pyright complains:
|
Why is |
According to the doc-string of
|
I'm very uncomfortable with the amount of "defensive" code in Trio. |
The |
Either we could annotate it like so or we could add type ignores (what we had before); might as well be type safe as this should be guaranteed to work (and if it doesn't that's indicative of a type checker bug somewhere). I'm not sure why pyright is erroring though -- it looks like it's wrong about the |
It's not so much protection against misuse, but it's because the implementation there doesn't type check without it - since |
And another weird one (the code is completely non-sensical, I just reduced it to the minimum): import array
import socket
import trio
async def echo_server(server_stream: trio.SocketStream):
fdarray = array.array("i", [server_stream.socket.fileno()])
await server_stream.socket.sendmsg(
[b"\x00"], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, fdarray)]
) results in:
it seems as if it thinks the first argument would be self; ie detects function vs method wrongly? |
Platform is fedora F8, Python 3.11.4, Pyright 1.1.325. Pyright executed with no flags on the code above (that is the whole code. Will test #2774 later today. |
#2774 does not fix the reported issue from above. |
Ah, I was only testing with |
The error is due to Lines 1002 to 1009 in d3255a0
it's maaaybe microsoft/pyright#4843 but it's not the same error, so I'm not sure. I'm not entirely sure what the wrapping is for in |
Replacing
I'd also love to hear the usecase for |
|
We could probably use Setting |
All reports in the issue should be fixed now, as far as I know. Any more testing of types would be appreciated! |
trio
now has some level of typed-ness! Unfortunately, we did not just copy overtrio-typing
meaning the type hints are slightly different.If your project:
trio-typing
or some custom type stubs (!?!)trio
versionthen please help us check our new typed interface by checking your code against
git+https://github.com/python-trio/trio
and telling us your results here!I expect a couple minor-ish typing changes before releasing 0.23.0 (the current state of things should be final-ish.TypeVarTuple
s, #2761, and fixes for any type issues) butThe text was updated successfully, but these errors were encountered: