Opened 7 years ago
Last modified 3 years ago
#27880 new Cleanup/optimization
Use __set_name__ to replace some usages of contribute_to_class.
Reported by: | Simon Charette | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | python3.6 |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If we were to define __set__name__ calling contribute_to_class()
on models.Field
, Manager
and Options
the following things could be done:
ModelBase.add_to_class
calls could be replaced by simplesetattr(cls, name, value)
.Options.contribute_to_class
could be inlined inOptions.__set_name__
.Manager.contribute_to_class
could be inlined inManager.__set_name__
.- There might be a way to inline
Field.contribute_to_class
by dealing with itsprivate_only
flag somehow.
Note:
See TracTickets
for help on using tickets.