🐛 fix: remove unused __future__ import (to resolve pyright type errors)
Starting with version 0.0.26, users of pyright (strict mode) encounter a typing error. For more details, please refer to discussion #1598.
This occurs when importing Field and can be resolved by removing the unnecessary from __future__ import annotations.
User Code (to reproduce this bug)
from sqlmodel import Field # <- pyright error occurs here
# do something
pyright app
/root/sqlmodel/app/test.py
/root/sqlmodel/app/test.py:1:22 - error: 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]" (reportUnknownVariableType)
1 errors, 0 warnings, 0 informations
I apologize for the confusing PR log. I don't know how to add labels.
To fix failure CI, https://github.com/fastapi/sqlmodel/pull/1603 must be merged.
To fix failure CI, #1603 must be merged.
The unrelated CI failures were fixed by https://github.com/fastapi/sqlmodel/pull/1613.
However, we'll still have an issue here: Python 3.9 tests fail due to mypy warnings around the | syntax (i.e. the import removed by this PR was there for a reason...)
Hi, there's some discussion here: https://github.com/fastapi/sqlmodel/discussions/1598 I have tracked down the root cause and proposed a fix (but I don't really know if its right). It does not remove the annotation.