Skip to content
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

Restore inner class Meta in models where it is accessible #2168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

intgr
Copy link
Collaborator

@intgr intgr commented May 16, 2024

I have made things!

Turns out that the inner Meta class is accessible for some models, but not others. Added class Meta only to stub model classes where it's accessible from outside (e.g. AbstractBaseUser.Meta does not crash with AttributeError). Used a hacky script at https://gist.github.com/intgr/352cac61b4f95e921bb33a0d4b76d324. See #2112 (comment) for details.

Related issues

intgr added 3 commits May 16, 2024 22:50
Turns out that the inner `Meta` class is accessible for some models, but not others. Added `class Meta` only to stub model classes where it's accessible from outside (e.g. `AbstractBaseUser.Meta` does not crash with AttributeError).
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I am lost! :)

So, what will happen now if we inherit some model with existing Meta and create our own Meta?
Can we:

  1. Inherit Meta as well as in class MyModel(SomeModel): class Meta(SomeModel.Meta)?
  2. Or do we have to use # type: ignore?
  3. Can we use .Meta on these types?

Do we need to test any of these?

class Meta:
verbose_name: str
verbose_name_plural: str
abstract: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Literal[True]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using Literal[True] here won't help anyone, to the contrary.

If the user subclasses this Meta and sets abstract = False, mypy will consider that a type error since it's not True. But it would be perfectly legal usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

AbstractUser lacks Meta-attribute
2 participants