Description
I am getting Pylance type-checking warnings when trying to use STRUCT
. My code looks like this:
...
Column(
"analysis_filter",
ARRAY(STRUCT(dimension=String, values=ARRAY(STRUCT(value=String)))),
),
...
Pylance underlines dimension=String
and gives this warning:
Argument of type "Type[String]" cannot be assigned to parameter "dimension" of type "Mapping[str, TypeEngine]" in function "__init__"
"Type[type]" is incompatible with "Type[Mapping[str, TypeEngine]]"
And similar warnings for values=ARRAY(...)
and value=String
.
I think the problem might be wrong types for the args in the STRUCT.__init__()
function. That function is declared in _struct.py as follows:
def __init__(
self,
*fields: Tuple[str, sqlalchemy.types.TypeEngine],
**kwfields: Mapping[str, sqlalchemy.types.TypeEngine],
):
But according to PEP 484, types for *args
and **kwargs
should be the type of a single argument, not the Tuple
or Dict
type of args
or kwargs
itself (see https://peps.python.org/pep-0484/#arbitrary-argument-lists-and-default-argument-values).
So I think **kwfields
should be declared like this:
**kwfields: sqlalchemy.types.TypeEngine,
I don't know how *fields
should be declared. I'm not sure whether it's possible to specify different types for the individual elements of *args
. Maybe this function shouldn't use *args
and should use two explicitly defined arguments instead?