Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Nov 26, 2024

Fixes #10970.

Because we make use of @dataclass_transform(), the method is synthesized by type checkers already. This fixes an issue with mypy and the Pydantic plugin, as the plugin removes the dataclass_transform spec from BaseModel subclasses, but not for RootModel which uses a different metaclass, and led to override issues with the synthesized __replace__ for root models and the BaseModel.__replace__ definition.

Change Summary

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Because we make use of `@dataclass_transform()`, the method is
synthesized by type checkers already. This fixes an issue with
mypy and the Pydantic plugin, as the plugin removes the
`dataclass_transform` spec from `BaseModel` subclasses,
but not for `RootModel` that uses a different metaclass.
@Viicos Viicos enabled auto-merge (squash) November 26, 2024 10:22
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Nov 26, 2024
Copy link

codspeed-hq bot commented Nov 26, 2024

CodSpeed Performance Report

Merging #10979 will not alter performance

Comparing replace-mypy (86657f0) with main (eec33b4)

Summary

✅ 46 untouched benchmarks

Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  main.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Viicos :)

@Viicos Viicos merged commit 4fffffe into main Nov 26, 2024
55 checks passed
@Viicos Viicos deleted the replace-mypy branch November 26, 2024 12:05
sydney-runkle pushed a commit that referenced this pull request Nov 26, 2024
Because we make use of `@dataclass_transform()`, the method is synthesized by type checkers already. This fixes an issue with mypy and the Pydantic plugin, as the plugin removes the `dataclass_transform` spec from `BaseModel` subclasses, but not for `RootModel` which uses a different metaclass, and led to override issues with the synthesized `__replace__` for root models and the `BaseModel.__replace__` definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signature of "__replace__" incompatible - RootModel
2 participants