sqlalchemy / sqlalchemy2-stubs

PEP-484 typing stubs for SQLAlchemy 1.4
MIT License
159 stars 41 forks source link

Fixed typing error in `session.get`. #221

Closed amisadmin closed 2 years ago

amisadmin commented 2 years ago

The type '_T' has been defined as the 'Union[Connection, Engine]' type in the 'Session' class.

Description

Checklist

This pull request is:

Have a nice day!

CaselIT commented 2 years ago

Hi,

not sure what you mean by

The type '_T' has been defined as the 'Union[Connection, Engine]' type in the 'Session' class.

_T is a free typevar so it can take any value

Note that I'm not against merging this, since it should not have any unexpected side effect, just trying to understand the rationale

amisadmin commented 2 years ago

Hi,

not sure what you mean by

The type '_T' has been defined as the 'Union[Connection, Engine]' type in the 'Session' class.

_T is a free typevar so it can take any value

Note that I'm not against merging this, since it should not have any unexpected side effect, just trying to understand the rationale

The Session class inherits from the _SessionNoIoTypingCommon(Generic[_T]) Generic class. And when we defined _SessionTypingCommon, we already bound _T to the Union[Connection, Engine] type. So, in the _SessionTypingCommon class and its subclasses, _T is of type Union[Connection, Engine].

4W67{5P D$IOTIYS6W92QXY

amisadmin commented 2 years ago

I tested the previous source and found that _T gets the correct inferred type in VSCode but gets the wrong inferred type in Pycharm.

CaselIT commented 2 years ago

I tested the previous source and found that _T gets the correct inferred type in VSCode but gets the wrong inferred type in Pycharm.

Ok, so this is a pycharm quirk. Thanks for clarifying.