Comments (14)
If we add a
impl<T: IntoPyTuple> IntoPyTuple for Option<T> {
fn into_tuple(self, py: Python) -> Py<PyTuple> {
match self {
Some(v) => v.into_tuple(py),
None => PyTuple::empty(py)
}
}
}
We can use None
instead of NoArgs
from pyo3.
Super! Let's do that
from pyo3.
Unfortunately
error[E0282]: type annotations needed
--> tests/test_class.rs:118:26
|
118 | assert!(typeobj.call(None, None).unwrap().cast_as::<EmptyClassWithNew>().is_ok());
| ^^^^ cannot infer type for `T`
error: aborting due to previous error(s)
call(args, kwargs)
can't use None
as args because into_typle
can't infer type for T
(None
is a variant of Option
while NoArgs
is a struct). So we stuck with ()
or NoArgs
.
from pyo3.
What if you use NoArgs as T
?
from pyo3.
Ah, nevermind
from pyo3.
is it possible to use default generic type parameter?
from pyo3.
I am not sure what you mean by default generic type parameter
.
from pyo3.
https://github.com/rust-lang/rust/blob/master/src/test/run-pass/generic-default-type-params.rs
from pyo3.
from pyo3.
default generic type parameter seems only allowed in type declaration now.
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions.
--> src/objectprotocol.rs:250:13
|
250 | fn call<A = ()>(&self, args: A, kwargs: Option<&PyDict>) -> PyResult<&PyObjectRef>
| ^
|
= note: #[deny(invalid_type_param_default)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
error: aborting due to previous error(s)
error: Could not compile `pyo3`.
from pyo3.
If we change call
signature to
fn call<A>(&self, args: A, kwargs: Option<&PyDict>) -> PyResult<&PyObjectRef>
where A: Into<Option<Py<PyTuple>>>
Use should be able to pass None
, Some(PyTuple::xxx)
and PyTuple::xxx
since Option
has the following impl since 1.12.0:
impl<T> From<T> for Option<T>
https://doc.rust-lang.org/src/core/option.rs.html#854-858
But that would require user to provide a PyTuple
object.
from pyo3.
I think it would reduce usability. i use IntoPyTuple
much more often, plus NoArg
is not big deal
from pyo3.
we can play with associated types, similar to class protocols. but I am not sure if it could be implemented
from pyo3.
lets close this issue, NoArgs
is not priority at the moment.
from pyo3.
Related Issues (20)
- Improve CI performance HOT 5
- Missing line in documentation
- `chrono::DateTime::to_object()` can panic HOT 2
- Unable to use async functions with multiple arguments in #[pymethods]
- Compile errors with 0.21.1 HOT 6
- 0.22 release HOT 1
- `PyUnicode_DATA` and related APIs need to be disabled on PyPy HOT 1
- Contribution opportunity: improved conversion traits HOT 10
- Fail before calling `Py_Initialize` on `PyPy`. HOT 2
- [0.21.1] Compilation error if async method has more than 2 args HOT 1
- expose `GILGuard` for RAII usage with a `map` method HOT 9
- Compilation error implementing dunder (magic) methods (__contains__) HOT 4
- `Borrowed<PyType>::name` is not consistent HOT 4
- Improve performance for `PyByteArray::new` HOT 5
- `#[pyo3::pymodule]` triggers missing documentation for a module lint HOT 3
- python ld flags not detected... HOT 6
- Declarative modules don't set item's module properly HOT 1
- Unable to mutate nested class values in python HOT 3
- build issue: Generated module PyInit releases GIL, then crashes [solved] HOT 4
- pyo3-0.20.2 fails to build on systems without AtomicI64 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyo3.