Skip to content

What to do with Optional types? #23

@ilevkivskyi

Description

@ilevkivskyi

There are several things typed as X in current stubs while in reality the type is Optional[X]. One such thing (probably one of the most important) is Column. Just making the inferred type Optional would cause loads of false positives.

A possible solution is to use nullable keyword to distinguish these (and probably primary_key), for example:

class User(Base):
    id = Column(Integer(), primary_key=True)
    name = Column(String(), nullable=False)
    nickname = Column(String())

user: User
revreal_type(user.id)  # Revealed type is 'int'
reveal_type(user.name)  # Revealed type is 'str'
reveal_type(user.name)  # Revealed type is 'Optional[str]'

cc @jhance who might be interested in this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions