You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Though every instance of a subclass of BaseCursor is an instance of BaseCursor, as an abstract class, BaseCursor isn't instantiable, and if it were, a concrete instance of the BaseCursor could not be used in place of any of the subclasses.
Proposed Solution
Replace BaseCursor with a CursorType TypeVar, which is bound to BaseCursor
Minimal Example to recreate:
Create a class which wraps the cursor, type-hinting the specific cursor type you wish to use.
(Type hinting any BaseCursor subclass results in the error):
Run mypy on the given file
mypy .
Result:
Cause of error
BaseCursor
is type hinted as the return value of the Connection.cursor method in ``Though every instance of a subclass of
BaseCursor
is an instance of BaseCursor, as an abstract class, BaseCursor isn't instantiable, and if it were, a concrete instance of the BaseCursor could not be used in place of any of the subclasses.Proposed Solution
Replace
BaseCursor
with a CursorTypeTypeVar
, which is bound toBaseCursor
Define the TypeVar
Replace BaseCursor with the type var in the type signature for
Connection.cursor
method and the type hint for the constructor'scursor_class
argumentEDIT:
It appears the solution isn't as straightforward as I thought. Digging in further....
The text was updated successfully, but these errors were encountered: