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

PyLance import of inner packages works incorrectly #801

Closed
wvolkov opened this issue Jan 4, 2021 · 17 comments
Closed

PyLance import of inner packages works incorrectly #801

wvolkov opened this issue Jan 4, 2021 · 17 comments
Labels
waiting for upstream Waiting for upstream to release a fix

Comments

@wvolkov
Copy link

wvolkov commented Jan 4, 2021

Environment data

  • Language Server version: Pylance language server 2020.12.2
  • OS and version: Windows_NT x64 10.0.19041
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.9
  • WSL: Ubuntu 20.04
  • VS Code: 1.52.1

Expected behaviour

  1. pip install asyncpg
  2. import asyncpg
  3. pylance will show class PosrtgesError after hitting psycopg.Post at editor

Actual behaviour

  1. pylance intellisence doesn't seem to find that class:
    inner import

while it still can show that via inner class exceptions:

inner import via inner module

Code Snippet / Additional information

import asyncpg
asyncpg.PostgresError

If we look at inner structure at asyncpg module (available at github here)
there is a mention of that class via all reference but with tuple, not list:

# ... at 13 line
__all__ = ('PostgresError', 'FatalPostgresError', 'UnknownPostgresError',
           'InterfaceError', 'InterfaceWarning', 'PostgresLogMessage',
           'InternalClientError', 'OutdatedSchemaCacheError', 'ProtocolError',
           'UnsupportedClientFeatureError')
# ...

maybe that is the way of it is not working properly.

@github-actions github-actions bot added the triage label Jan 4, 2021
@wvolkov wvolkov changed the title PyLance import of inner packages works incorrect PyLance import of inner packages works incorrectly Jan 4, 2021
@judej judej added the needs investigation Could be an issue - needs investigation label Jan 4, 2021
@github-actions github-actions bot removed the triage label Jan 4, 2021
@jakebailey
Copy link
Member

Curious, I think a tuple should work. If you go and edit the file to be a list, does it work?

@erictraut Do you know off the top of your head if we are strict about it only being a list?

@erictraut
Copy link
Contributor

We support lists and tuples. You can find a list of all supported idioms here.

@jakebailey
Copy link
Member

Thanks for the clarification. We'll have to look closer at this one, then.

@wvolkov

This comment has been minimized.

@jakebailey

This comment has been minimized.

@bschnurr
Copy link
Member

if you look at asyncpg.__init__.py you'll see they are dynamically building __all__

__all__ = (
    ('connect', 'create_pool', 'Pool', 'Record', 'Connection')
    + exceptions.__all__  # NOQA
)

@jakebailey
Copy link
Member

Hm, this should be one of the patterns we support.

@bschnurr
Copy link
Member

bschnurr commented Sep 15, 2021

ahh. PostgresError isn't in that list. oh correction its another indirection _base.__all__

in exceptions\__init__.py

__all__ = _base.__all__ + (

@jakebailey
Copy link
Member

But, __all__ is for import *, so it's omission there may or may not imply it should be externally visible.

@erictraut
Copy link
Contributor

No, this isn't a pattern we support. This example is using using a nested tuple expression within a tuple expression.

@erictraut
Copy link
Contributor

Here's the specific set of patterns that we support: https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface

So this would work:

__all__ = ['connect', 'create_pool', 'Pool', 'Record', 'Connection']
__all__.extend(exceptions.__all__)

@jakebailey
Copy link
Member

Maybe I'm missing something but it's just parenthesis at the top level; it's functionally equivalent to ('foo', 'bar') + something.__all__.

@erictraut
Copy link
Contributor

At the point where we handle __all__, we have no type information. We're looking for very specific parse tree patterns. It's very strict. It's not feasible for us to handle deviations. That's why we explicitly defined (and standardized) the list of patterns that we support.

@jakebailey
Copy link
Member

Sure. I was just surprised that this was one we didn't handle.

@bschnurr bschnurr added waiting for upstream Waiting for upstream to release a fix and removed needs investigation Could be an issue - needs investigation labels Sep 15, 2021
@bschnurr
Copy link
Member

This seems like a bug after I edit asyncpg/exceptions/__init__.py

doens't work

__all__ = _base.__all__

works

__all__ = []
__all__.extend(_base.__all__)

where _base.all is

__all__ = ['PostgresError', 'FatalPostgresError', 'UnknownPostgresError',
           'InterfaceError', 'InterfaceWarning', 'PostgresLogMessage',
           'InternalClientError', 'OutdatedSchemaCacheError', 'ProtocolError',
           'UnsupportedClientFeatureError']

@erictraut
Copy link
Contributor

__all__ = _base.__all__ is not a pattern we support. The very specific list of supported patterns is here: https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface. If you stick to the list of standardized supported patterns, it will work fine.

@bschnurr
Copy link
Member

yup. thank you. i'm submitting a change to asyncpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for upstream Waiting for upstream to release a fix
Projects
None yet
Development

No branches or pull requests

6 participants