Skip to content

Conversation

@AlanBogarin
Copy link
Contributor

Add type hint for sa_column (Column[Unknown])

Add type hint for sa_column (Column[Unknown])
@iloveitaly
Copy link

What problem does this fix? More helpful PR descriptions may help this get merged.

@AlanBogarin
Copy link
Contributor Author

What problem does this fix? More helpful PR descriptions may help this get merged.

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

remove type ignore flag
@AlanBogarin AlanBogarin changed the title Update main.py Fix sqlmodel.Field partially unknown Nov 26, 2024
@AlanBogarin AlanBogarin changed the title Fix sqlmodel.Field partially unknown Update main.py Nov 26, 2024
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.

2 participants