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

Regression of #63? Need type annotation for <relationship> #200

Open
posita opened this issue Jan 15, 2022 · 0 comments
Open

Regression of #63? Need type annotation for <relationship> #200

posita opened this issue Jan 15, 2022 · 0 comments
Labels
requires triage New issue that requires categorization

Comments

@posita
Copy link

posita commented Jan 15, 2022

#63 is closed as a duplicate of sqlalchemy/sqlalchemy#6255, which is closed as fixed. However, the problem still occurs:

# test_case.py
from __future__ import annotations

from sqlalchemy import Column, ForeignKey, Integer, MetaData
from sqlalchemy.orm import registry, relationship
from sqlalchemy.orm.decl_api import DeclarativeMeta

# See
# <https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#creating-an-explicit-base-non-dynamically-for-use-with-mypy-similar>.
mapper_registry = registry(
    metadata=MetaData(schema="test_db"),
)


class Base(metaclass=DeclarativeMeta):
    __abstract__ = True

    # these are supplied by the sqlalchemy2-stubs, so may be omitted
    # when they are installed
    registry = mapper_registry
    metadata = mapper_registry.metadata

    __init__ = mapper_registry.constructor


# Taken verbatim from <https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html#many-to-one>.
class Parent(Base):
    __tablename__ = "parent"
    id = Column(Integer, primary_key=True)
    child_id = Column(Integer, ForeignKey("child.id"))
    child = relationship("Child")


class Child(Base):
    __tablename__ = "child"
    id = Column(Integer, primary_key=True)
% python --version
Python 3.9.9
% mypy --version
mypy 0.931
% pip list | grep -i alchemy
SQLAlchemy        1.4.29
sqlalchemy2-stubs 0.0.2a19
% mypy --config=/dev/null test_case.py
/dev/null: No [mypy] section in config file
test_case.py:31: error: Need type annotation for "child"
Found 1 error in 1 file (checked 1 source file)
@posita posita added the requires triage New issue that requires categorization label Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires triage New issue that requires categorization
Projects
None yet
Development

No branches or pull requests

1 participant