sqlalchemy2-stubs
sqlalchemy2-stubs copied to clipboard
Another file's variable is not defined error
trafficstars
ref: #14
If i use declared_attr in the upper mixin class, i get Name "Carrier" is not defined error.
Using import like below, which is not used anywhere, fixes the error, but this is not the way I want it to be.
# models.py
if TYPE_CHECKING:
from module.to.carrier import Carrier
My code in mixin.py
@declarative_mixin
class DeliveryRefundPolicyMixin:
@declared_attr
def default_carrier(cls) -> Mapped["Carrier"]:
return relationship("Carrier", primaryjoin="Carrier.id==%s.default_carrier_id" % cls.__name__)
models.py
class ProductBase(AbstractBase, DeliveryRefundPolicyMixin):
__abstract__ = True
models.py not using Carrier anywhere but got not defined error in models.py