Opened 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: master
Severity: Normal Keywords: python3.6
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If we were to define __set__name__ calling contribute_to_class() on models.Field, Manager and Options the following things could be done:

  1. ModelBase.add_to_class calls could be replaced by simple setattr(cls, name, value).
  2. Options.contribute_to_class could be inlined in Options.__set_name__.
  3. Manager.contribute_to_class could be inlined in Manager.__set_name__.
  4. There might be a way to inline Field.contribute_to_class by dealing with its private_only flag somehow.

Change History (0)

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