Skip to content

SQLAlchemy Session __enter__ and __exit__ methods not being noticed. #2088

Closed
@howbazaar

Description

@howbazaar

Environment data

  • Language Server version: 2021.11.1
  • OS and version: linux x64
  • Python version: cpython 3.8
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: basic

Expected behaviour

We have a session builder being used, and a method new_session:

from sqlalchemy.orm import Session
#...
    @staticmethod
    def new_session() -> Session:
        dbm = DBManagerBuilder()
        Session = dbm().get_session()
        return Session()

All places in the code where we call this method should be error free:

    with rdb.new_session() as session:

Actual behaviour

All places in the code where we call this method

    with rdb.new_session() as session:

gets red squiggly lines under the rdb.new_session()

Object of type "Session" cannot be used with "with" because it does not implement __enter__PylancereportGeneralTypeIssues
Object of type "Session" cannot be used with "with" because it does not implement __exit__PylancereportGeneralTypeIssues
(method) new_session: () -> Session

Following the Session definition through, the __enter__ and __exit__ methods are clearly there.

Logs

Python Language Server Log

XXX 'Please paste the output from your clipboard'
typeshed-fallback/stdlib/logging/__init__.pyi [fs read 0ms] (28ms)
[FG] binding: /home/tim/.vscode/extensions/ms-python.vscode-pylance-2021.11.1/dist/typeshed-fallback/stdlib/logging/__init__.pyi (6ms)
[FG] parsing: /home/tim/.vscode/extensions/ms-python.vscode-pylance-2021.11.1/dist/bundled/stubs/sqlalchemy/orm/__init__.pyi [fs read 0ms] (2ms)
[FG] binding: /home/tim/.vscode/extensions/ms-python.vscode-pylance-2021.11.1/dist/bundled/stubs/sqlalchemy/orm/__init__.pyi (1ms)
[FG] parsing: /home/tim/.vscode/extensions/ms-python.vscode-pylance-2021.11.1/dist/bundled/stubs/sqlalchemy/orm/session.pyi [fs read 1ms] (13ms)
[FG] binding: /home/tim/.vscode/extensions/ms-python.vscode-pylance-2021.11.1/dist/bundled/stubs/sqlalchemy/orm/session.pyi (3ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange

I'm guessing that the stubs being bundled don't specify the enter and exit methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypestubIssue relating to our bundled type stubswaiting for upstreamWaiting for upstream to release a fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions