]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: only use covariant Row type variable 306/head
authorDenis Laxalde <denis@laxalde.org>
Mon, 16 May 2022 17:16:53 +0000 (19:16 +0200)
committerDenis Laxalde <denis@laxalde.org>
Thu, 19 May 2022 17:42:12 +0000 (19:42 +0200)
commit2f6e7669f0b32e7a99dd6db0ef41a18af119909f
tree19df2df90071d485ceb3c8fd815f9fdf1c7407cb
parent1fe058c7bfabce6fd26fb6534afe8a30d42ba242
fix: only use covariant Row type variable

The real variance of Row type variable is covariant, per definition of
RowMaker (RowMaker[B] is a subtype of RowMaker[A] if B is a subtype of
A; similar to the Box type in [mypy documentation][]).

By dropping the Row type variable from Cursor argument in RowFactory, we
are now able to only use the covariant Row variable (previously Row_co,
now Row). Indeed, RowFactory does not actually depend on Cursor on being
parametrized on Row; rather it's the other way around (Cursor's Row type
variable comes from its row factory).

[mypy documentation]: https://mypy.readthedocs.io/en/latest/generics.html#variance-of-generic-types
docs/advanced/rows.rst
psycopg/psycopg/rows.py
tests/test_typing.py