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 column __init__ args typing for EventSchemaTarget #73

Merged
merged 8 commits into from
Apr 29, 2021

Conversation

MaicoTimmerman
Copy link
Contributor

@MaicoTimmerman MaicoTimmerman commented Apr 23, 2021

Description

Fix Column.__init__ for *args

Checklist

Test-case:

from sqlalchemy import Column, ForeignKey, Sequence
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.orm import registry, Mapped

reg: registry = registry()


@reg.mapped
class InferredNames:
    __tablename__ = "infered"

    # Instantiated type
    id = Column(Integer(), primary_key=True)

    # Non-instantiated type
    name = Column(String, nullable=False)

    # SchemaItem
    foreign: Mapped[int] = Column(ForeignKey("infered.id"))

    # SchemaItem without type
    foreign1: Mapped[int] = Column(ForeignKey("infered.id"))

    # SchemaItem without type
    foreign2: Mapped[int] = Column(Integer, ForeignKey("infered.id"))

    # sequence
    seq = Column(Integer, Sequence("my_sequence"), primary_key=True)

    # type is None
    # TODO This still crashes the plugin, even though the docstring says is valid
    # Column(None, ForeignKey("addresses.id")),


@reg.mapped
class ExplicitNames:
    __tablename__ = "explicit"

    # Instantiated type
    id = Column("id", Integer(), primary_key=True)

    # Non-instantiated type
    name = Column("name", String, nullable=False)

    # SchemaItem without type
    foreign1: int = Column("foreign", ForeignKey("infered.id"))

    # SchemaItem without type
    foreign2: int = Column("foreign", Integer, ForeignKey("infered.id"))

    # sequence
    seq = Column(Integer, Sequence("my_sequence"), primary_key=True)

    # type is None
    # TODO This still crashes the plugin, even though the docstring says is valid
    # none_type = Column("none_type", None, ForeignKey("addresses.id"))

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@MaicoTimmerman
Copy link
Contributor Author

Validated with python -m mypy.stubtest sqlalchemy.sql.schema and the test-cases in /sqlalchemy/test/ext/mypy/files

@@ -425,6 +425,7 @@ class ColumnClause(
roles.StrAsPlainColumnRole,
Immutable,
NamedColumn,
Generic[_TE],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taken care of in #37

sqlalchemy-stubs/sql/schema.pyi Outdated Show resolved Hide resolved
sqlalchemy-stubs/sql/schema.pyi Outdated Show resolved Hide resolved
@CaselIT CaselIT merged commit 842350d into sqlalchemy:master Apr 29, 2021
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.

4 participants