Add the __enter__ and __exit__ methods to Session.#231
Add the __enter__ and __exit__ methods to Session.#231howbazaar wants to merge 1 commit intodropbox:masterfrom
Conversation
| binds: Optional[Any] = ..., extension: Optional[Any] = ..., | ||
| info: Optional[Any] = ..., query_cls: Any = ...) -> None: ... | ||
| connection_callable: Any = ... | ||
| def __enter__(self): ... |
There was a problem hiding this comment.
The return type annotation is missing.
There was a problem hiding this comment.
This was copied from the SessionTransaction above. I matched the style there.
There was a problem hiding this comment.
| def __enter__(self): ... | |
| def __enter__(self) -> Session: ... |
There was a problem hiding this comment.
This one is actually pretty important, as it tells Pylance/Pylint what type session is in
with Session() as session:
| info: Optional[Any] = ..., query_cls: Any = ...) -> None: ... | ||
| connection_callable: Any = ... | ||
| def __enter__(self): ... | ||
| def __exit__(self, type, value, traceback): ... |
There was a problem hiding this comment.
The parameter and return type annotations are missing.
There was a problem hiding this comment.
| def __exit__(self, type, value, traceback): ... | |
| def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: ... |
|
|
|
Any update on that issue? I'm trying to use mypy + pydantic + sqlalchemy in a project and needing to write |
I'm here for the same reason. It's been almost a year since this was submitted. |
As per https://github.com/sqlalchemy/sqlalchemy/blame/958f902b1fc528fed0be550bc573545de47ed854/lib/sqlalchemy/orm/session.py#L1131 the
Sessionobject has had__enter__and__exit__for about 17 months.