Opened 9 years ago

Closed 9 years ago

#6214 closed (fixed)

Small cleanup in models.base

Reported by: Ivan Illarionov Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

fixed # TODO: Checking for the presence of '_meta' is hackish.

Attachments (4)

models.base.diff (528 bytes) - added by Ivan Illarionov 9 years ago.
fixes the previous patch
optimized.models.base.diff (1.1 KB) - added by Ivan Illarionov 9 years ago.
small optimization of previous patch
evenmoreoptimized.models.base.diff (4.6 KB) - added by Ivan Illarionov 9 years ago.
even more optimisations
models.base-11-01-2008.diff (4.6 KB) - added by Ivan Illarionov 9 years ago.
filter(lambda b...) changed to list comprehension

Download all attachments as: .zip

Change History (12)

comment:1 Changed 9 years ago by Ivan Illarionov

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Since each base can only be a Model subclass it always has the same metaclass and therefore always has a _meta attribute except the Model class itself.

comment:2 Changed 9 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

Push to a design decision, since this sounds about right but such a core change needs a bit of thinking.

comment:3 Changed 9 years ago by Ivan Illarionov

I can also suggest the renaming of the first argument of ModelBase.__new__ from cls to metacls for clarity, because it really is a ModelBase metaclass. It can be a source of confusion in future development and for people trying to understand what's happening since it's not clear from the code that cls here is NOT a newly created Model or Model-based class.

Oh, and ModelBase can be renamed to something like _ModelMetaclass because it is not a BASE class for Model it is a CLASS of Model class. And with first underscore if it is not intended for importing or customization.

comment:4 Changed 9 years ago by Ivan Illarionov

And, if we are talking about the design decision, I would also note that classmethods of Model (add_to_class and _prepare) can be safely moved to its metaclass as normal (not class) methods. It has the advantage of separating the logic of Model classes and Model instances.

comment:5 Changed 9 years ago by Chris Beaven

Perhaps you could try to get a discussion going in the django-dev group.

Changed 9 years ago by Ivan Illarionov

Attachment: models.base.diff added

fixes the previous patch

comment:6 Changed 9 years ago by Ivan Illarionov

I mistakenly thought that only Model subclasses can be in bases. New patch fixes this.

Changed 9 years ago by Ivan Illarionov

Attachment: optimized.models.base.diff added

small optimization of previous patch

Changed 9 years ago by Ivan Illarionov

even more optimisations

Changed 9 years ago by Ivan Illarionov

Attachment: models.base-11-01-2008.diff added

filter(lambda b...) changed to list comprehension

comment:8 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7098]) Fixed #6214 -- Added some small optimisations to model class initialisation.
Thanks, Ivan Illarionov.

Note: See TracTickets for help on using tickets.
Back to Top