Skip to content

Conversation

davidhewitt
Copy link
Contributor

@davidhewitt davidhewitt commented Jul 12, 2023

Change Summary

mypy doesn't appear to be happy with the way the slots_dataclass wraps dataclass. I think it fails to recognise the annotated class as a dataclass.

In this PR I propose an alternative way to switch slots for Python 3.10 and up by just passing a mapping **slots_true to the standard dataclass constructor. (The mapping is {'slots': True} on 3.10 and up, otherwise empty.)

Related issue number

Fixes #6544

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 and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @samuelcolvin

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 13, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d402f86
Status: ✅  Deploy successful!
Preview URL: https://3175a966.pydantic-docs2.pages.dev
Branch Preview URL: https://dh-slots-dataclass.pydantic-docs2.pages.dev

View logs

@davidhewitt
Copy link
Contributor Author

please review

@samuelcolvin samuelcolvin merged commit 8fa9678 into main Jul 13, 2023
@samuelcolvin samuelcolvin deleted the dh/slots-dataclass branch July 13, 2023 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mypy errors when BeforeValidator is assigned to a variable before being used in tp.Annotated
2 participants