Skip to content

Commit fb17d5e

Browse files
authored
Merge pull request #683 from kngwyu/pyclass-new-layout
New #[pyclass] system that is aware of its concrete layout
2 parents 95d045f + 439efbb commit fb17d5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1590
-1244
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
* The blanket implementations for `FromPyObject` for `&T` and `&mut T` are no longer specializable. Implement `PyTryFrom` for your type to control the behavior of `FromPyObject::extract()` for your types.
1313
* The implementation for `IntoPy<U> for T` where `U: FromPy<T>` is no longer specializable. Control the behavior of this via the implementation of `FromPy`.
14+
* `#[new]` does not take `PyRawObject` and can reutrn `Self` [#683](https://github.com/PyO3/pyo3/pull/683)
1415

1516
### Added
1617

1718
* Implemented `IntoIterator` for `PySet` and `PyFrozenSet`. [#716](https://github.com/PyO3/pyo3/pull/716)
19+
* `PyClass`, `PyClassShell`, `PyObjectLayout`, `PyClassInitializer` [#683](https://github.com/PyO3/pyo3/pull/683)
1820

1921
### Fixed
2022

2123
* Clear error indicator when the exception is handled on the Rust side. [#719](https://github.com/PyO3/pyo3/pull/719)
2224

25+
### Removed
26+
27+
* `PyRef`, `PyRefMut`, `PyRawObject` [#683](https://github.com/PyO3/pyo3/pull/683)
28+
2329
## [0.8.5]
2430

2531
* Support for `#[name = "foo"]` attribute for `#[pyfunction]` and in `#[pymethods]`. [#692](https://github.com/PyO3/pyo3/pull/692)

examples/rustapi_module/src/buf_and_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct BytesExtractor {}
99
#[pymethods]
1010
impl BytesExtractor {
1111
#[new]
12-
pub fn __new__(obj: &PyRawObject) {
13-
obj.init({ BytesExtractor {} });
12+
pub fn __new__() -> Self {
13+
BytesExtractor {}
1414
}
1515

1616
pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult<usize> {

examples/rustapi_module/src/datetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ pub struct TzClass {}
195195
#[pymethods]
196196
impl TzClass {
197197
#[new]
198-
fn new(obj: &PyRawObject) {
199-
obj.init(TzClass {})
198+
fn new() -> Self {
199+
TzClass {}
200200
}
201201

202202
fn utcoffset<'p>(&self, py: Python<'p>, _dt: &PyDateTime) -> PyResult<&'p PyDelta> {

examples/rustapi_module/src/dict_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub struct DictSize {
1616
#[pymethods]
1717
impl DictSize {
1818
#[new]
19-
fn new(obj: &PyRawObject, expected: u32) {
20-
obj.init(DictSize { expected })
19+
fn new(expected: u32) -> Self {
20+
DictSize { expected }
2121
}
2222

2323
fn iter_dict(&mut self, _py: Python<'_>, dict: &PyDict) -> PyResult<u32> {

examples/rustapi_module/src/othermod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ pub struct ModClass {
1313
#[pymethods]
1414
impl ModClass {
1515
#[new]
16-
fn new(obj: &PyRawObject) {
17-
obj.init(ModClass {
16+
fn new() -> Self {
17+
ModClass {
1818
_somefield: String::from("contents"),
19-
})
19+
}
2020
}
2121

2222
fn noop(&self, x: usize) -> usize {

examples/rustapi_module/src/subclassing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub struct Subclassable {}
88
#[pymethods]
99
impl Subclassable {
1010
#[new]
11-
fn new(obj: &PyRawObject) {
12-
obj.init(Subclassable {});
11+
fn new() -> Self {
12+
Subclassable {}
1313
}
1414
}
1515

examples/word-count/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ struct WordCounter {
1616
#[pymethods]
1717
impl WordCounter {
1818
#[new]
19-
fn new(obj: &PyRawObject, path: String) {
20-
obj.init(WordCounter {
19+
fn new(path: String) -> Self {
20+
WordCounter {
2121
path: PathBuf::from(path),
22-
});
22+
}
2323
}
2424

2525
/// Searches for the word, parallelized by rayon

0 commit comments

Comments
 (0)