-
Notifications
You must be signed in to change notification settings - Fork 876
Introspection: Basic pyclass(extends) support #5331
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Introspection: emit base classes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SubDict(dict): | ||
def __new__(cls, /) -> None: ... | ||
def __str__(self, /) -> str: ... | ||
|
||
class Subclass(Subclassable): | ||
def __new__(cls, /) -> None: ... | ||
def __str__(self, /) -> str: ... | ||
|
||
class Subclassable: | ||
def __new__(cls, /) -> None: ... | ||
def __str__(self, /) -> str: ... | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
from pyo3_pytests.subclassing import Subclassable | ||
from pyo3_pytests.subclassing import Subclassable, Subclass | ||
|
||
|
||
class SomeSubClass(Subclassable): | ||
def __str__(self): | ||
return "SomeSubclass" | ||
|
||
|
||
def test_subclassing(): | ||
def test_python_subclassing(): | ||
a = SomeSubClass() | ||
assert str(a) == "SomeSubclass" | ||
assert type(a) is SomeSubClass | ||
|
||
|
||
def test_rust_subclassing(): | ||
a = Subclass() | ||
assert str(a) == "Subclass" | ||
assert type(a) is Subclass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1139,6 +1139,8 @@ pub trait PyClassBaseType: Sized { | |
type BaseNativeType; | ||
type Initializer: PyObjectInit<Self>; | ||
type PyClassMutability: PyClassMutability; | ||
/// Fully qualified name of the base class including modules | ||
const BASE_NAME: &'static str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not gated this associated constants with the I have not reused Happy to rename the constant to something better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this information suitable to get from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. I would need to fix the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, that's a good point. I think that's probably just a historical mistake, it also leads to a lot of sad error messages where we leak the I think doing that as a precursor PR might be desirable? I can try to do so later, perhaps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Thanks! It will actually be also useful to generate some type stubs. I hope to be able to do it today, feel free to focus on something else. |
||
} | ||
|
||
/// Implementation of tp_dealloc for pyclasses without gc | ||
|
Uh oh!
There was an error while loading. Please reload this page.