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

Manage inheritance correctly #4

Closed
tmke8 opened this issue Mar 5, 2023 · 4 comments · Fixed by #21
Closed

Manage inheritance correctly #4

tmke8 opened this issue Mar 5, 2023 · 4 comments · Fixed by #21
Labels
enhancement New feature or request

Comments

@tmke8
Copy link
Owner

tmke8 commented Mar 5, 2023

Only Generic and other TypeEnums should be allowed. See how it's done with TypedDict: https://github.com/python/cpython/blob/32220543e2db36c6146ff2704ed1714a6adecc1b/Lib/typing.py#L2931

@tmke8 tmke8 added the enhancement New feature or request label Mar 5, 2023
@tmke8
Copy link
Owner Author

tmke8 commented Mar 6, 2023

Actually, maybe inheriting from other TypeEnums also shouldn't be allowed because this will mess up the exhaustiveness check.

@tmke8 tmke8 changed the title Disallow inheriting from other classes Manage inheritance correctly Mar 6, 2023
@tmke8
Copy link
Owner Author

tmke8 commented Mar 6, 2023

It should work like this: You can do inheritance but the inner types of a subclass are not members of the base class. So, BgColor.transparent is not a subclass of Color even if BgColor inherits from Color.

@tmke8
Copy link
Owner Author

tmke8 commented Mar 6, 2023

There is another point: T.A should actually have all the attributes that T has, otherwise it's really not appropriate to call it a subclass. So, you can access A also through T.A.A and so on.

@tmke8
Copy link
Owner Author

tmke8 commented Mar 7, 2023

Note also, that if we have

class Color(TypeEnum):
    rgb = (int, int, int)
class BgColor(Color):
    hsv = (int, int, int)

then BgColor should not be a subclass of Color:

assert not issubclass(BgColor, Color)

which is admittedly a bit weird... but otherwise BgColor.hsv would be a subtype of Color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant