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

Add the __enter__ and __exit__ methods to Session. #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sqlalchemy-stubs/orm/session.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Session(_SessionClassMethods):
binds: Optional[Any] = ..., extension: Optional[Any] = ...,
info: Optional[Any] = ..., query_cls: Any = ...) -> None: ...
connection_callable: Any = ...
def __enter__(self): ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation is missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied from the SessionTransaction above. I matched the style there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __enter__(self): ...
def __enter__(self) -> Session: ...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is actually pretty important, as it tells Pylance/Pylint what type session is in

with Session() as session: 

def __exit__(self, type, value, traceback): ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter and return type annotations are missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this method.

Copy link

@jkeiser jkeiser Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __exit__(self, type, value, traceback): ...
def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: ...

@property
def info(self): ...
def begin(self, subtransactions: bool = ..., nested: bool = ...) -> SessionTransaction: ...
Expand Down