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

type inference for client object not working with async with - determine root cause #285

Closed
cprice404 opened this issue Feb 23, 2023 · 2 comments · Fixed by #297
Closed
Assignees

Comments

@cprice404
Copy link
Collaborator

cprice404 commented Feb 23, 2023

Michael reported that using an async with ... as clause in VSCode, the editor was not inferring the type of the CacheClient. That would be a pretty big deal for VSCode users.

We should try this in IDEA/PyCharm to narrow down the cause; if it works there then we can maybe rule out it being a library issue, and assume that it is something VSCode specific.

Either way, if we can't get it working in VSCode we may want to update our example code to account for this (e.g. don't use async with, just do a normal variable assignment and then an explicit close/exit? Or see if you can add a mypy type hint after the as clause?

@malandis
Copy link
Contributor

The root cause is import visibility rules used by pylance. See here #281 (comment).

This possibly explains the issue seen in IntelliJ with the match statements as well. To fix I will apply both redundant type aliases in __init__ files and also specify __all__. The __all__ specifications will allow users to type from momento.responses import *. Though this is discouraged by python, some users may expect it, and it also makes the names public.

@malandis
Copy link
Contributor

related: #296

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 a pull request may close this issue.

2 participants