-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🔥 Remove _base_class_defined
hack in favor of an empty bases check
#5761
Conversation
please review |
I'll just note this may be in tension with some of the goals of #5740 — simplifying the MRO etc. I like getting rid of the hacky check for subclass of BaseModel, but I don't have a strong opinion about what's best here (or whether there might be other unintended consequences, especially for performance). Happy to defer to @adriangb or @samuelcolvin |
I think, it would be even better. I'm happy to remove |
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'm okay with this in principle, but better if we can reduce the size of the change.
pydantic/main.py
Outdated
# track of whether we've created the `BaseModel` class yet, and therefore whether it's safe to refer to it. If | ||
# it *hasn't* been created, we assume that the `__new__` call we're in the middle of is for the `BaseModel` | ||
# class, since that's defined immediately after the metaclass. | ||
if bases == (_BaseModelBase,): |
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.
can we change this to if bases != ...
and then revert most of these changes here?
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've minimized the changeset.
IMO, it would be nice to have
if condition:
# a couple of lines for a special case
return
# a lot of lines for the main body
return
instead of
if condition:
# a lot of lines for the main body
return
else:
# a couple of lines for a special case
return
53eeb5b
to
1c5b48f
Compare
Deploying with Cloudflare Pages
|
1c5b48f
to
f814d6b
Compare
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.
_base_class_defined
hack in favor of a marker base class_base_class_defined
hack in favor of an empty bases check
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'm good with the change, I just think the big comment that seems to have been moved verbatim probably deserves an update before merging.
f814d6b
to
afde015
Compare
afde015
to
c109adb
Compare
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Change Summary
Remove
_base_class_defined
hack and check for emptybases
as an indicator for detectingBaseModel
inModelMetaclass
. These classes are no longer tied to their places in the module.Related issue number
None
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)
Selected Reviewer: @adriangb