dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
570 stars 101 forks source link

Column comment type #238

Open sdfordham opened 2 years ago

sdfordham commented 2 years ago

Running the SQLAlchemy inspect method on an existing MySQL server on a table with a column with an empty comment field is returning comment=None so I guess comment to be Optional[str] but mypy output complains that it needs to be str. Actually I don't know why since the repo code shows:

https://github.com/dropbox/sqlalchemy-stubs/blob/80f89322c3a58c1a8c19588b17869c5f49a1e72b/sqlalchemy-stubs/sql/schema.pyi#L88

Here is a MWE:

from sqlalchemy import Column
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class MyTable(Base):
    id = Column('id', comment=None)

and output:

test.py:10: error: No overload variant of "Column" matches argument types "str", "None"
test.py:10: note: Possible overload variants:
test.py:10: note:     def [_T] Column(self, name: str, type_: Type[TypeEngine[_T]], *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
test.py:10: note:     def [_T] Column(self, name: str, type_: TypeEngine[_T], *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
test.py:10: note:     def [_T] Column(self, name: str, type_: ForeignKey, *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = 
..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
.., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
test.py:10: note:     def [_T] Column(self, type_: TypeEngine[_T], *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
test.py:10: note:     def [_T] Column(self, type_: ForeignKey, *args: Any, autoincrement: Union[bool, str] = ..., default: Any = ..., doc: str = ..., key: str = ..., index: bool = ..., info: Mapping[str, Any] = ..., nullable: bool = ..., onupdate: Any = ..., primary_key: bool = ..., server_default: Any = ..., server_onupdate: Union[FetchedValue, FunctionElement[Any]] = ..., quote: Optional[bool] = ..., unique: bool = ..., system: bool = ..., comment: str = ...) -> Column[_T]
Found 1 error in 1 file (checked 1 source file)