Hello Mike,

Yes that’s using the plugin: 
sqlalchemy[mypy,postgresql_psycopg2binary]==1.4.29 I changed the function 
declaration to this:

    @staticmethod
    def create(dbsession: Session, name: str, id_: 
typing.Union[uuid.UUID, sqlalchemy.dialects.postgresql.base.UUID] = None):

and it seems to work. In a similar vain, how do I manage the types of 
mapped and unmapped objects? Following the above example:

user = User(dbsession, "Joe Black")

returns an unmapped, simple User object. Now suppose I have another 
existing, mapped User object and would like to assign that  newly created 
unmapped user:

other_user.spouse = user

which creates the following error:

error: Argument "spouse" to "User" has incompatible type "User"; expected 
"Mapped[Any]"  [arg-type]

Declaring that column with:

spouse: typing.Union[Mapped[User], User] = relationship("User", 
back_populates="spouse", uselist=False)

seems to work; I just want to make sure that that’s a recommended way of 
going about this? Should I always declare a type as a Union between a 
mapped and unmapped same class?

Other than following the migration guide 
<https://docs.sqlalchemy.org/en/14/changelog/migration_20.html>, I haven’t 
looked into SQLA2 <https://github.com/sqlalchemy/sqlalchemy/projects/3>.
Jens


On Thursday, January 13, 2022 at 11:52:18 PM UTC+10 Mike Bayer wrote:

> is this with the SQLAlchemy Mypy plugin?   current status is for 2.0 we 
> are looking to move away from the plugin model and pretty much change how 
> these things work.    Otherwise  if this is with the plugin, you would use 
> "id: Mapped[uuid.UUID] = ..."
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/5ccd954f-277f-4f4e-adc1-2d7a906b9c09n%40googlegroups.com.

Reply via email to