Skip to content
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

Pyright reports false positive error with asynccontextmanager #87

Merged
merged 2 commits into from
Dec 5, 2021

Conversation

sdwilsh
Copy link
Contributor

@sdwilsh sdwilsh commented Nov 7, 2021

Pyright gets confused and will give you error messages like this:

error: Object of type "AsyncIterator[AsyncGenerator[...]]" cannot be used with "with" because it does not implement __aenter__ (reportGeneralTypeIssues)
error: Object of type "AsyncIterator[AsyncGenerator[...]]" cannot be used with "with" because it does not implement __aexit__ (reportGeneralTypeIssues)

For code like this:

async with Client("test.mosquitto.org") as client:
    async with client.filtered_messages("floors/+/humidity") as messages:
        await client.subscribe("floors/#")
        async for message in messages:
            print(message.payload.decode())

This change statically checks against sys.version_info for the right version, which Pyright understands.

For additional discussion, see encode/httpx#1829.

Pyright gets confused and will give you error messages like this:
```
error: Object of type "AsyncIterator[AsyncGenerator[...]]" cannot be used with "with" because it does not implement __aenter__ (reportGeneralTypeIssues)
error: Object of type "AsyncIterator[AsyncGenerator[...]]" cannot be used with "with" because it does not implement __aexit__ (reportGeneralTypeIssues)
```
For code like this:
```python
async with Client("test.mosquitto.org") as client:
    async with client.filtered_messages("floors/+/humidity") as messages:
        await client.subscribe("floors/#")
        async for message in messages:
            print(message.payload.decode())
```

This change statically checks against `sys.version_info` for the right version, which Pyright understands.
@sdwilsh
Copy link
Contributor Author

sdwilsh commented Nov 7, 2021

Whoops...I had checked for issues on this, but failed to check PRs. It looks like #86 by @laundmo is an alternative fix for this as well.

@frederikaalund
Copy link
Collaborator

Thanks for opening this pull request. There is a lot of overlap with #86, yes, so let's take the discussion in there. 👍 Seems to me that @laundmo is open to your approach. Let's discuss in #86. :)

@frederikaalund
Copy link
Collaborator

After some discussion in #86, I chose to merge #86 first. That puts this PR (#87) in conflict.

I'd like to merge it in, though. I think it's trivial to make it compatible with the current master. Can you please update this PR accordingly? Thanks! :)

@frederikaalund frederikaalund merged commit d0fd6b4 into empicano:master Dec 5, 2021
@frederikaalund
Copy link
Collaborator

Looks good to me. :) Thank you for your contribution to asyncio-mqtt. 👍

@sdwilsh
Copy link
Contributor Author

sdwilsh commented Dec 31, 2021

@frederikaalund, any thoughts on when you might be cutting a new release?

@frederikaalund
Copy link
Collaborator

@sdwilsh, I'll make a new release first thing on Monday. :) I just need to update the changelog accordingly. Should take 10 mins.

@frederikaalund
Copy link
Collaborator

I just released v0.11.1. Better late than never. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants