Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sqlmodel.Field partially unknown #1227

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlanBogarin
Copy link

Type checker throw partially unknown error when used in strict mode (Pylance)
When I locally edited that line, everything was correct

origin: sqlmodel.main.Field
info: Column expected an argument

339 |    sa_column: Union[Column, UndefinedType] = Undefined,  # type: ignore

proposed change

339 |    sa_column: Union[Column[Any], UndefinedType] = Undefined,

If you want to see it yourself (be sure to set the type checker to strict)

import sqlmodel

class TestModel(sqlmodel.SQLModel, table=True):
    value: list[int] = sqlmodel.Field(sa_column=sqlmodel.Column(sqlmodel.JSON))

There is a better change, but it is not possible because Column was defined in sqlalchemy

# sqlalchemy.sql.schema
113 |    _T = TypeVar("_T", bound="Any", default="Any")  # python >= 3.13

Add type hint for sa_column (Column[Unknown])
remove type ignore flag
@AlanBogarin AlanBogarin marked this pull request as ready for review November 26, 2024 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant