Subclass's Meta should inherit from parent class's Meta
Every time the generated code contains a structure similar to:
class A:
class Meta:
pass
class B(A):
class Meta:
pass
I get a static type-checker warning about B.Meta being an incorrect override for A.Meta. To fix this, simply change the above to:
class A:
class Meta:
pass
class B(A):
class Meta(A.Meta):
pass
Can you give some more info about the type-checker you are using?
Unfortunately this isn't really an option as the Meta class must be final to avoid conflicts
@tefra It's Pyright, take a look here.
Thanks @sashkent3 from quick look a lot of libraries suffer from that issue
https://github.com/microsoft/pyright/discussions/6570 https://github.com/typeddjango/django-stubs/issues/748
I am open to suggestions but inheritance between Meta classes is impossible
@tefra could you kindly clarify what do you mean by:
Meta class must be final
Also, if xsdata intends to ignore this warning, maybe it's better to simply generate type: ignore alongside?
The parent class might not have a meta class, but the parent parent might, resolving the imports is very hard in these cases.
Maybe the type: ignore is the way to go let me think about it.
Isn't it feasible to generate class Meta for every class? Even in cases where it's currently not needed.
If we create a Meta class for every model and include all the properties in each one, doesn’t that undermine the point of using inheritance, which is to share and build on common attributes efficiently?
I am not sure I like adding more code/noise just to satisfy pyright
Well, that's fair, but I believe this is about more than satisfying Pyright. When you do:
class A:
class Meta:
pass
class B(A):
pass
The B class inherits A.Meta whether you intend it or not. The following two pieces of code are exactly equivalent, because B.Meta is A.Meta:
class C(B):
class Meta(B.Meta):
pass
and
class C(B):
class Meta(A.Meta):
pass