Replies: 3 comments 1 reply
-
|
This is caused by |
Beta Was this translation helpful? Give feedback.
-
|
I think this might also be related and/or to pyright 1.1.407 specifically |
Beta Was this translation helpful? Give feedback.
-
|
I tracked down why this is happening but I don't know the best solution. I don't know how it would affect older versions and tests, but adding an The relevant part of the import block now looks like this: from ._compat import ( # type: ignore[attr-defined]
IS_PYDANTIC_V2,
PYDANTIC_MINOR_VERSION,
BaseConfig,
ModelField,
ModelMetaclass,
Representation,
SQLModelConfig,
_calculate_keys,
finish_init,
get_annotations,
get_config_value,
get_field_metadata,
get_model_fields,
get_relationship_to,
get_sa_type_from_field,
init_pydantic_private_attrs,
is_field_noneable,
is_table_model_class,
post_init_field_info,
set_config_value,
sqlmodel_init,
sqlmodel_validate,
)
from .sql.sqltypes import AutoString
if TYPE_CHECKING:
from pydantic._internal._model_construction import ModelMetaclass as ModelMetaclass
from pydantic._internal._repr import Representation as Representation
from pydantic_core import PydanticUndefined as Undefined
from pydantic_core import PydanticUndefinedType as UndefinedType
else:
from ._compat import Undefined, UndefinedTypeThoughts? I can submit a PR to see if it still passes tests, if you want; though I feel this is just a band-aid to a larger issue... As far as I understand pydantic_core didn't exist until pydantic v2, so the type checker will get mad at the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
From 0.0.26 onwards, importing/using
sqlmodel.Fieldand having pyright/basedpyright in "strict" mode causes the type checker to report an error. This means that I either have to set atype: ignoreor dial back the overall type "strict-ness" in a project to stop the LSP from complaining.Full example:
(the code above saved as "main.py")
pyproject.toml - minimal just to set "strict" mode for type-checking
run with version 0.0.25 - no errors or warnings reported (as expected)
pip install --quiet sqlmodel==0.0.25 && pyrightversion 0.0.26 fails with
reportUnknownVariableTypepip install --quiet sqlmodel==0.0.26 && pyrightOperating System
macOS
Operating System Details
No response
SQLModel Version
0.0.26
Python Version
3.13.7
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions