-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Mark old xType aliases as deprecated #3288
base: main
Are you sure you want to change the base?
Mark old xType aliases as deprecated #3288
Conversation
Doesn't touch JoystickType because the C code still works the old way I think, doesn't touch CameraType because CameraType is not in the stubs. In fact CameraType might be removable as an internal implementation detail.
class EventType: | ||
# Duplicated Event fields here because it is marked as final and can't be | ||
# subclassed like the other xType aliases are to allow @deprecated. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how all other instances are elegantly marked as deprecated without duplication, and there's there's this that sticks out.
I get why it's done, but can we find a workaround that doesn't need the duplication? Something like
EventType = deprecated("Use
Event instead (this is an old alias)")(Event)
should be a one-liner that could work? If it does, this style could be used everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a clever idea, but I get a stubtest error.
error: pygame.event.EventType variable differs from runtime type builtins.type
Stub: in file C:\Users\charl\Desktop\pygame-ce\buildconfig\stubs\pygame\event.pyi:29
def (type: builtins.int, dict: builtins.dict[builtins.str, Any] =, **kwargs: Any) -> pygame.event.Event
Runtime:
<class 'pygame.event.Event'>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did get it almost perfect with
class _EventStuff:
@property
def type(self) -> int: ...
__dict__: dict[str, Any]
__hash__: None # type: ignore
def __init__(
self, type: int, dict: dict[str, Any] = ..., **kwargs: Any
) -> None: ...
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
def __bool__(self) -> bool: ...
# this is at the bottom because mypy complains if this declaration comes
# before any uses of the dict[] typehinting because of the same naming
@property
def dict(self) -> dict[str, Any]: ...
@final
class Event(_EventStuff):
pass
@final
@deprecated("Use `Event` instead (this is an old alias)")
class EventType(_EventStuff):
pass
The problem is that _EventStuff is also exported, shows up in the list of suggestions when typing pygame.event. I tried del _EventStuff
but that didn't change it.
Starts to handle #3239
It would be a huge pain to put in deprecation warnings about this, but the deprecation decorator is easy and we're now using it in other places so lets use it here.
Doesn't touch JoystickType because the C code still works the old way I think, doesn't touch CameraType because CameraType is not in the stubs. In fact CameraType might be removable as an internal implementation detail.