-
Notifications
You must be signed in to change notification settings - Fork 177
Construct instance of appropriate class in Event._init #752
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
base: main
Are you sure you want to change the base?
Conversation
/ok to test eb6890b |
@@ -89,7 +89,7 @@ cdef class Event: | |||
|
|||
@classmethod | |||
def _init(cls, device_id: int, ctx_handle: Context, options=None): | |||
cdef Event self = Event.__new__(Event) | |||
cdef Event self = Event.__new__(cls) |
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.
This ensures that a cls
instance is produced here, which could be different from Event
if cls
is a subclass.
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 think this works! I was trying:
cdef cls self = Event.__new__(cls)
and getting compile time errors.
|
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.
This same fix should also be applied to the Stream
class.
@@ -89,7 +89,7 @@ cdef class Event: | |||
|
|||
@classmethod | |||
def _init(cls, device_id: int, ctx_handle: Context, options=None): | |||
cdef Event self = Event.__new__(Event) | |||
cdef Event self = Event.__new__(cls) |
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.
Can we add a test for a derived class of Event to ensure that we don't accidentally regress on what this enables?
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.
We can go about this in two ways:
- Write a test that invokes
MyEvent.__new__
directly and test that it produces aMyEvent
(easy) - Write a test that monkeypatches
Event
toMyEvent
, and test that constructing an event viaStream
orDevice
produces aMyEvent
rather than anEvent
(more complex, but representative of how users can actually use subclasses).
Ultimately, (2) calls down to (1) but in a way that's an implementation detail. Any preferences?
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.
Lets take the easy path and we can always revisit in the future if we see value in doing so.
Description
Closes #750
closes
Checklist