Skip to content

Support initializing root model fields with values of the root type in the mypy plugin #11212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Jan 3, 2025

Also use the TypeInfo.has_base method instead of iterating over the MRO in various places.

Closes #11203.

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

… in the mypy plugin

Also use the `TypeInfo.has_base` method instead of iterating over the MRO
in various places.
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jan 3, 2025
Copy link

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9dd8b0a
Status: ✅  Deploy successful!
Preview URL: https://37172f3c.pydantic-docs.pages.dev
Branch Preview URL: https://root-model-plugin.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Jan 3, 2025

CodSpeed Performance Report

Merging #11212 will not alter performance

Comparing root-model-plugin (9dd8b0a) with main (aa85c3a)

Summary

✅ 46 untouched benchmarks

Copy link
Contributor

github-actions bot commented Jan 3, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  mypy.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.

This LGTM overall (thanks for adding the tests, those made the impact here quite clear), but let's have @dmontagu take a look as well given his familiarity with the mypy plugin.

@Viicos Viicos merged commit bfeca9b into main Jan 8, 2025
62 checks passed
@Viicos Viicos deleted the root-model-plugin branch January 8, 2025 16:02
@antoniogamizdelgado
Copy link

Hello! We have started noticing these errors:

monolith/records2/company_definition/domain/badger_object/fields/field_error.py:26: error: Item "str" of "FieldName | str" has no attribute "root"  [union-attr]

Can this change be the cause of these new error? It was working fine last week.

@antoniogamizdelgado
Copy link

Indeed, rolling back to 2.10.6 and this problem does not appear. So I guess this has pretty much broken our mypy checks :(

@Viicos
Copy link
Member Author

Viicos commented Mar 31, 2025

@antoniogamizdelgado please open a new issue with a MRE.

@antoniogamizdelgado
Copy link

@Viicos done (#11657)

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.

Enable mypy plugin to support initializing RootModel fields with values of the generic's type when init_typed=True
4 participants