| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
This is caused by from __future__ import annotations in main.py added by #1560 |
|
I think this might also be related and/or to pyright 1.1.407 specifically |
|
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 else clause to the if TYPE_CHECKING statement and importing UndefinedType and Undefined from ._compat in that block, while removing them from the ._compat import above fixes the issue pyright is having. It seems like pyright is evaluating the if-else block in ._compat to be a union of the possible types in the if IS_PYDANTIC_V2: ... else: ... clause, not the ones that are actually present based on the version installed. 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 if TYPE_CHECKING block in main.py if pydantic v1 is in use anyway. Is pydantic v1 support a priority moving forward with this project? |
|
Any updates on the error? If someone is wondering about the complete error message - Type of "Field" is partially unknown Type of "Field" is "Overload[(default: Any = Undefined, *, default_factory: (() -> Any) | None = None, alias: str | None = None, title: str | None = None, description: str | None = None, exclude: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, include: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, const: bool | None = None, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None, multiple_of: float | None = None, max_digits: int | None = None, decimal_places: int | None = None, min_items: int | None = None, max_items: int | None = None, unique_items: bool | None = None, min_length: int | None = None, max_length: int | None = None, allow_mutation: bool = True, regex: str | None = None, discriminator: str | None = None, repr: bool = True, primary_key: bool | Unknown | PydanticUndefinedType = Undefined, foreign_key: Any = Undefined, unique: bool | Unknown | PydanticUndefinedType = Undefined, nullable: bool | Unknown | PydanticUndefinedType = Undefined, index: bool | Unknown | PydanticUndefinedType = Undefined, sa_type: Type[Any] | Unknown | PydanticUndefinedType = Undefined, sa_column_args: Sequence[Any] | Unknown | PydanticUndefinedType = Undefined, sa_column_kwargs: Mapping[str, Any] | Unknown | PydanticUndefinedType = Undefined, schema_extra: Dict[str, Any] | None = None) -> Any, (default: Any = Undefined, *, default_factory: (() -> Any) | None = None, alias: str | None = None, title: str | None = None, description: str | None = None, exclude: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, include: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, const: bool | None = None, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None, multiple_of: float | None = None, max_digits: int | None = None, decimal_places: int | None = None, min_items: int | None = None, max_items: int | None = None, unique_items: bool | None = None, min_length: int | None = None, max_length: int | None = None, allow_mutation: bool = True, regex: str | None = None, discriminator: str | None = None, repr: bool = True, primary_key: bool | Unknown | PydanticUndefinedType = Undefined, foreign_key: str, ondelete: Unknown | PydanticUndefinedType | Literal['CASCADE', 'SET NULL', 'RESTRICT'] = Undefined, unique: bool | Unknown | PydanticUndefinedType = Undefined, nullable: bool | Unknown | PydanticUndefinedType = Undefined, index: bool | Unknown | PydanticUndefinedType = Undefined, sa_type: Type[Any] | Unknown | PydanticUndefinedType = Undefined, sa_column_args: Sequence[Any] | Unknown | PydanticUndefinedType = Undefined, sa_column_kwargs: Mapping[str, Any] | Unknown | PydanticUndefinedType = Undefined, schema_extra: Dict[str, Any] | None = None) -> Any, (default: Any = Undefined, *, default_factory: (() -> Any) | None = None, alias: str | None = None, title: str | None = None, description: str | None = None, exclude: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, include: AbstractSet[int | str] | Mapping[int | str, Any] | Any = None, const: bool | None = None, gt: float | None = None, ge: float | None = None, lt: float | None = None, le: float | None = None, multiple_of: float | None = None, max_digits: int | None = None, decimal_places: int | None = None, min_items: int | None = None, max_items: int | None = None, unique_items: bool | None = None, min_length: int | None = None, max_length: int | None = None, allow_mutation: bool = True, regex: str | None = None, discriminator: str | None = None, repr: bool = True, sa_column: Column[Any] | Unknown | PydanticUndefinedType = Undefined, schema_extra: Dict[str, Any] | None = None) -> Any]" |
|
This has been resolved, there is no errors in SQLModel 0.0.31 |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
{{editor}}'s edit
{{editor}}'s edit
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.Field and having pyright/basedpyright in "strict" mode causes the type checker to report an error. This means that I either have to set a type: ignore or 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 reportUnknownVariableType
pip 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