sqlalchemy: Mypy 1.1 type errors with dataclasses

Describe the typing issue

In mypy 1.1.1 we’re seeing a lot of typing errors along the lines of:

 auth.py:136: error: Argument "email" to "User" has incompatible type
"str"; expected "Mapped[str]"  [arg-type]
        user = User(email=email, ***

Errors are not present in mypy 1.0.0.

I suspect it has to do with some new features around dataclasses.

To Reproduce

# Base defined like:
class Base(MappedAsDataclass, DeclarativeBase):
    ...

Let me know if you can’t reproduce, and I’ll try to look into it further.

Versions

  • SQLAlchemy: 2.0.5

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 30 (29 by maintainers)

Commits related to this issue

Most upvoted comments

oh yes, putting the init=False inside the Annotated is not going to work, sorry. pep-681 needs to see mapped_column(init=False) inline inside the body of the class.

so yes that issue reprodcues on 2.0.5 and is now fixed