sqlalchemy2-stubs icon indicating copy to clipboard operation
sqlalchemy2-stubs copied to clipboard

Another file's variable is not defined error

Open xncbf opened this issue 3 years ago • 0 comments

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

xncbf avatar Dec 26 '21 08:12 xncbf