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
Warn and ignore __slots__
argument to create_model
#4432
Conversation
please review. |
__slots__
argument to create_model
Except the failing CI, LGTM 👍 |
I'll wait for @hot123s (author of #3946) and @PrettyWood to review, then I think we're ready for a final pre-release - |
# With python 3.8, specifically 3.8.10, Literal "is" check sare very flakey | ||
# can change on very subtle changes like use of types in other modules, | ||
# hopefully this check avoids that issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to know what is compiled behind the scene to understand how this edge case arrives. Such a weird bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, so weird.
The line that caused the issue again was __slots__: Optional[Tuple[str, ...]] = None,
, if I changed it to __slots__: 'Optional[Tuple[str, ...]]' = None,
it went again. But I decided this was a safer fix.
okay, I want to get the (hopefully) last pre-release out, so I'm going to merge this. |
Found while investigating error in litestar-org/litestar#401
Change Summary
In v1.9.2
__slots__
could be passed tocreate_model
, I'm not sure if it was honoured or ignored, but it didn't cause an error.In v1.10.0a2 however it caused a warning, and if that warning was ignored, an error creating the model.
This was happening here
Even more unusually, this only seemed to be an error if pydantic is compiled.
With this change a
RuntimeWarning
is raised, and__slots__
is then ignored.Related issue number
Caused by #3946 I think.