Support for subclassing Python objects#45
Conversation
|
I am wondering if this can feel more natural (i.e. hide the detail as much as possible) if we do this with The Alternatively, the API can use some kind of builder pattern: Obviously I am out of depth here, but just want to enumerate other design options available for supporting subclasses. |
|
@liuliu I have doubts that Mirror is that powerful, although I did think about it. That would be awesome, so please prove me wrong! A function builder API sounds cool, but it’s something that will build on what we have now. It could be a second initializer. I’m not going to spend much more time on this, but please put your ideas into action if you have the time. For defineMethod, properties are also members, as well as initializers. Your last idea is a little too much for PythonKit, which keeps things as simple as possible. |
|
@pvieito I haven't added proper tests for this yet. Should I add them before merging? |
|
@philipturner Yes, please! |
This comment has been minimized.
This comment has been minimized.
|
I got test #2 figured out. Subclassing a custom class requires a different syntax than |
Support for subclassing Python objects
I don't have a proper test suite yet. However, I did run through the PyTorch beginner tutorial. PyTorch relies heavily on subclassing and should be a good litmus test. I made this script and it runs successfully on arm64 macOS: gist. Pay attention to line 61 for an example of how to use subclassing.
This contains commits from the following pull requests. Therefore, there may be conflicts if you merge the following first:
CC: @liuliu @ephemer