Skip to content

Commit 7c0379b

Browse files
committed
Remove many specialization uses
From over a hundret "default fn" uses down to 17
1 parent 33e72a2 commit 7c0379b

34 files changed

+526
-1037
lines changed

CHANGELOG.md

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

99
### Changed
1010

11+
* Slowly removing specialization uses
1112
* All exceptions are consturcted with `py_err` instead of `new`, as they return `PyErr` and not `Self`.
1213
* `as_mut` and friends take and `&mut self` instead of `&self`
14+
* `ObjectProtocol::call` now takes an `Option<PyDict>` for the kwargs instead of an `IntoPyDictPointer`.
15+
* `IntoPyDictPointer` was replace by `IntoPyDict` which doesn't convert `PyDict` itself anymore and returns a `PyDict` instead of `*mut PyObject`.
1316

1417
### Fixed
1518

guide/src/conversions.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@ fn main() {
7676
}
7777
```
7878

79-
`kwargs` argument is generate over
80-
[`IntoPyDictPointer`][IntoPyDictPointer] trait. `HashMap` or `BTreeMap` could be used as
81-
keyword arguments. rust tuple with up to 10 elements where each element is tuple with size 2
82-
could be used as kwargs as well. Or `NoArgs` object can be used to indicate that
83-
no keywords arguments are provided.
79+
`kwargs` can by `None` or `Some(PyDict)`. You can use the
80+
[`IntoPyDict`][IntoPyDict] trait to convert other dict-like containers, e.g. `HashMap`, `BTreeMap` as well as tuples with up to 10 elements and `Vec`s where each element is a two element tuple.
8481

8582
```rust
8683
extern crate pyo3;
@@ -130,4 +127,4 @@ TODO
130127
[IntoPyTuple]: https://docs.rs/pyo3/0.2.7/trait.IntoPyTuple.html
131128
[PyTuple]: https://docs.rs/pyo3/0.2.7/struct.PyTuple.html
132129
[ObjectProtocol]: https://docs.rs/pyo3/0.2.7/trait.ObjectProtocol.html
133-
[IntoPyDictPointer]: https://docs.rs/pyo3/0.2.7/trait.IntoPyDictPointer.html
130+
[IntoPyDict]: https://docs.rs/pyo3/0.2.7/trait.IntoPyDict.html

src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ mod test {
720720
let array = py
721721
.import("array")
722722
.unwrap()
723-
.call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs)
723+
.call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), None)
724724
.unwrap();
725725
let buffer = PyBuffer::get(py, array.into()).unwrap();
726726
assert_eq!(buffer.dimensions(), 1);

src/class/async.rs

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,18 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> {
9191
#[cfg(Py_3)]
9292
#[doc(hidden)]
9393
pub trait PyAsyncProtocolImpl {
94-
fn tp_as_async() -> Option<ffi::PyAsyncMethods>;
95-
96-
fn methods() -> Vec<PyMethodDef>;
97-
}
98-
99-
#[cfg(Py_3)]
100-
impl<T> PyAsyncProtocolImpl for T {
101-
#[inline]
102-
default fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
94+
fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
10395
None
10496
}
10597

106-
#[inline]
107-
default fn methods() -> Vec<PyMethodDef> {
98+
fn methods() -> Vec<PyMethodDef> {
10899
Vec::new()
109100
}
110101
}
111102

103+
#[cfg(Py_3)]
104+
impl<T> PyAsyncProtocolImpl for T {}
105+
112106
#[cfg(Py_3)]
113107
impl<'p, T> PyAsyncProtocolImpl for T
114108
where
@@ -139,19 +133,13 @@ where
139133
}
140134

141135
trait PyAsyncAwaitProtocolImpl {
142-
fn am_await() -> Option<ffi::unaryfunc>;
143-
}
144-
145-
impl<'p, T> PyAsyncAwaitProtocolImpl for T
146-
where
147-
T: PyAsyncProtocol<'p>,
148-
{
149-
#[inline]
150-
default fn am_await() -> Option<ffi::unaryfunc> {
136+
fn am_await() -> Option<ffi::unaryfunc> {
151137
None
152138
}
153139
}
154140

141+
impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p> {}
142+
155143
impl<T> PyAsyncAwaitProtocolImpl for T
156144
where
157145
T: for<'p> PyAsyncAwaitProtocol<'p>,
@@ -168,19 +156,13 @@ where
168156
}
169157

170158
trait PyAsyncAiterProtocolImpl {
171-
fn am_aiter() -> Option<ffi::unaryfunc>;
172-
}
173-
174-
impl<'p, T> PyAsyncAiterProtocolImpl for T
175-
where
176-
T: PyAsyncProtocol<'p>,
177-
{
178-
#[inline]
179-
default fn am_aiter() -> Option<ffi::unaryfunc> {
159+
fn am_aiter() -> Option<ffi::unaryfunc> {
180160
None
181161
}
182162
}
183163

164+
impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p> {}
165+
184166
impl<T> PyAsyncAiterProtocolImpl for T
185167
where
186168
T: for<'p> PyAsyncAiterProtocol<'p>,
@@ -197,19 +179,13 @@ where
197179
}
198180

199181
trait PyAsyncAnextProtocolImpl {
200-
fn am_anext() -> Option<ffi::unaryfunc>;
201-
}
202-
203-
impl<'p, T> PyAsyncAnextProtocolImpl for T
204-
where
205-
T: PyAsyncProtocol<'p>,
206-
{
207-
#[inline]
208-
default fn am_anext() -> Option<ffi::unaryfunc> {
182+
fn am_anext() -> Option<ffi::unaryfunc> {
209183
None
210184
}
211185
}
212186

187+
impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> {}
188+
213189
#[cfg(Py_3)]
214190
mod anext {
215191
use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl};
@@ -260,29 +236,17 @@ mod anext {
260236
}
261237

262238
trait PyAsyncAenterProtocolImpl {
263-
fn __aenter__() -> Option<PyMethodDef>;
264-
}
265-
266-
impl<'p, T> PyAsyncAenterProtocolImpl for T
267-
where
268-
T: PyAsyncProtocol<'p>,
269-
{
270-
#[inline]
271-
default fn __aenter__() -> Option<PyMethodDef> {
239+
fn __aenter__() -> Option<PyMethodDef> {
272240
None
273241
}
274242
}
275243

276-
trait PyAsyncAexitProtocolImpl {
277-
fn __aexit__() -> Option<PyMethodDef>;
278-
}
244+
impl<'p, T> PyAsyncAenterProtocolImpl for T where T: PyAsyncProtocol<'p> {}
279245

280-
impl<'p, T> PyAsyncAexitProtocolImpl for T
281-
where
282-
T: PyAsyncProtocol<'p>,
283-
{
284-
#[inline]
285-
default fn __aexit__() -> Option<PyMethodDef> {
246+
trait PyAsyncAexitProtocolImpl {
247+
fn __aexit__() -> Option<PyMethodDef> {
286248
None
287249
}
288250
}
251+
252+
impl<'p, T> PyAsyncAexitProtocolImpl for T where T: PyAsyncProtocol<'p> {}

0 commit comments

Comments
 (0)