modelform_factory and __module__ name

28 views
Skip to first unread message

Silvio

unread,
Aug 29, 2022, 5:10:57 AM8/29/22
to Django developers (Contributions to Django itself)
Hi all,

Not quite sure if this is the right forum, but it concerns Django itself and static analysis of it.

I'm working heavily on static analysis of the Django code base, including mypy and Django-stubs.

For the life of me, I cannot figure out why the class returned by modelform_factory has "django.forms.widgets" as its __module__. I can see it having "django.forms.models" or the like, but the former makes no sense.

It's not a huge issue, as ultimately dynamic classes will have localized module names but it's been bugging me for a while.

Give it a try in a plain Django installation: model passed to modelform_factory and inspect the module name.

Best,

Silvio

Jörg Breitbart

unread,
Aug 29, 2022, 5:33:50 AM8/29/22
to django-d...@googlegroups.com
Looks to me like being carried forward from the very first metaclass
``MediaDefiningClass``, which happens to be defined in django.forms.widgets.

Should be fixable by explicitly adding a __module__ notion to type().

Not sure though if it is worth additional code just for the sake of
pretty __module__ alignment.

Silvio

unread,
Aug 29, 2022, 5:53:03 AM8/29/22
to Django developers (Contributions to Django itself)
That helps, thanks.

I don't think it's worth it either, because, ultimately, it'll still be "wrong". The right __module__ is wherever you called modelform_factory from.

The perils of meta programming...
Reply all
Reply to author
Forward
0 new messages