I have the following Python code which works fine (version 3.11). Why does PyLance complain about this?
import jinja2
templateEnv = jinja2.Environment(loader=jinja2.BaseLoader)
template = templateEnv.from_string(my_string)
PyLance v2024.2.2 in VS Code shows this error:
Argument of type "type[BaseLoader]" cannot be assigned to parameter "loader" of type "BaseLoader | None" in function "__init__"
Type "type[BaseLoader]" cannot be assigned to type "BaseLoader | None"
"type[type]" is incompatible with "type[BaseLoader]"
"type[type]" is incompatible with "type[None]"
https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType
PyLance expects an instance of
BaseLoaderclasss or its subclass forloaderargument, but in your code you pass the class itself and not instance of the class.If you don't need any specific loading behavior that requires subclassing
BaseLoader, you can simply instantiate it directly as follows: