title: SqlAlchemy Mypy undefined definition error
body: <p>I'm trying to use Mypy with SqlAlchemy, and following the docs as closely as possible. I've set up a 1-1 relationship, but am getting an error with the mypy plugin:</p>
  <pre class="lang-py prettyprint-override"><code>class UserModel(Base):
      &quot;&quot;&quot;
      Primary USER table
      user_id: Unique Integer
      user_name: Unique Username
      user_created_date: Date when user registered (datetime)
      is_active: Boolean
      &quot;&quot;&quot;
  
      __tablename__ = &quot;user&quot;
  
      id: int = Column(Integer, primary_key=True, index=True, autoincrement=True)
      email: str = Column(String(30), index=True, nullable=False)
      time_created = Column(DateTime(timezone=True), server_default=func.now())
      time_updated = Column(DateTime(timezone=True), onupdate=func.now())
      is_active: bool = Column(Boolean, default=True)
      user_authentication = relationship(
          &quot;UserAuthenticationModel&quot;,
          back_populates=&quot;user&quot;,
          uselist=False,
      ) # Error is here - [SQLAlchemy Mypy plugin] Can't infer type from ORM mapped expression assigned to attribute 'user_authentication'; please specify a Python type or Mapped[&lt;python type&gt;] on the left hand side.
  
  
  class UserAuthenticationModel(Base):
      &quot;&quot;&quot;
      Usertable for authentication purpose
      user_id: Unique Integer
      user_password: String(100)
      user_uses_2fa: Boolean
      user_email_verified: Boolean
      &quot;&quot;&quot;
  
      __tablename__ = &quot;user_authentication&quot;
  
      id: int = Column(Integer, primary_key=True, index=True, autoincrement=True)
      user_id: int = Column(Integer, ForeignKey(&quot;user.id&quot;), primary_key=True)
      password: str = Column(String(100), nullable=False)
      uses_2fa: bool = Column(Boolean, default=False)
      user_email_verified: bool = Column(Boolean, default=False)
      associated_user: UserModel = relationship(&quot;UserModel&quot;, back_populates=&quot;user_authentication&quot;)
  </code></pre>
  <p>The problem is, if I type the user_authentication field like this:</p>
  <pre class="lang-py prettyprint-override"><code>user_authentication: UserAuthenticationModel
  </code></pre>
  <p>the model is undefined on the line (because I then go on to define it below). I'm not sure how to get around this problem - any help would be appreciated.</p>