From 8a22d5bdaa6ee3fa6767f6b5f72a8f1add18cb46 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 13 Mar 2021 17:36:17 +0000 Subject: [PATCH] pymodule: remove call_function etc. --- CHANGELOG.md | 2 +- src/types/module.rs | 99 ++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 290d0378219..34af181cd50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Deprecate FFI definitions `PyModule_GetFilename`. [#1425](https://github.com/PyO3/pyo3/pull/1425) - The `auto-initialize` feature is no longer enabled by default. [#1443](https://github.com/PyO3/pyo3/pull/1443) - Change `PyCFunction::new()` and `PyCFunction::new_with_keywords()` to take `&'static str` arguments rather than implicitly copying (and leaking) them. [#1450](https://github.com/PyO3/pyo3/pull/1450) -- The `call/call0/call1` methods of `PyModule` have been renamed to `call_function` etc. for consistency with `call` and `call_method` on `PyAny`. The old names are still present, but deprecated. [#1467](https://github.com/PyO3/pyo3/pull/1467) +- Deprecate `PyModule` methods `call`, `call0`, `call1` and `get`. [#1492](https://github.com/PyO3/pyo3/pull/1492) ### Removed - Remove deprecated exception names `BaseException` etc. [#1426](https://github.com/PyO3/pyo3/pull/1426) diff --git a/src/types/module.rs b/src/types/module.rs index ec9c2e189b6..fd9758e2f16 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -129,65 +129,6 @@ impl PyModule { } } - /// Calls a function in the module. - /// - /// This is equivalent to the Python expression `module.name(*args, **kwargs)`. - pub fn call_function( - &self, - name: &str, - args: impl IntoPy>, - kwargs: Option<&PyDict>, - ) -> PyResult<&PyAny> { - self.getattr(name)?.call(args, kwargs) - } - - /// Calls a function in the module with only positional arguments. - /// - /// This is equivalent to the Python expression `module.name(*args)`. - pub fn call_function1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny> { - self.getattr(name)?.call1(args) - } - - /// Calls a function in the module without arguments. - /// - /// This is equivalent to the Python expression `module.name()`. - pub fn call_function0(&self, name: &str) -> PyResult<&PyAny> { - self.getattr(name)?.call0() - } - - #[deprecated(since = "0.14.0", note = "Renamed to call_function() for consistency.")] - pub fn call( - &self, - name: &str, - args: impl IntoPy>, - kwargs: Option<&PyDict>, - ) -> PyResult<&PyAny> { - self.call_function(name, args, kwargs) - } - - #[deprecated( - since = "0.14.0", - note = "Renamed to call_function1() for consistency." - )] - pub fn call1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny> { - self.call_function1(name, args) - } - - #[deprecated( - since = "0.14.0", - note = "Renamed to call_function0() for consistency." - )] - pub fn call0(&self, name: &str) -> PyResult<&PyAny> { - self.call_function0(name) - } - - /// Gets a member from the module. - /// - /// This is equivalent to the Python expression `module.name`. - pub fn get(&self, name: &str) -> PyResult<&PyAny> { - self.getattr(name) - } - /// Adds a member to the module. /// /// This is a convenience function which can be used from the module's initialization function. @@ -310,4 +251,44 @@ impl PyModule { let name = fun.getattr("__name__")?.extract()?; self.add(name, fun) } + + /// Calls a function in the module. + /// + /// This is equivalent to the Python expression `module.name(*args, **kwargs)`. + #[deprecated( + since = "0.14.0", + note = "use getattr(name)?.call(args, kwargs) instead" + )] + pub fn call( + &self, + name: &str, + args: impl IntoPy>, + kwargs: Option<&PyDict>, + ) -> PyResult<&PyAny> { + self.getattr(name)?.call(args, kwargs) + } + + /// Calls a function in the module with only positional arguments. + /// + /// This is equivalent to the Python expression `module.name(*args)`. + #[deprecated(since = "0.14.0", note = "use getattr(name)?.call1(args) instead")] + pub fn call1(&self, name: &str, args: impl IntoPy>) -> PyResult<&PyAny> { + self.getattr(name)?.call1(args) + } + + /// Calls a function in the module without arguments. + /// + /// This is equivalent to the Python expression `module.name()`. + #[deprecated(since = "0.14.0", note = "use getattr(name)?.call0() instead")] + pub fn call0(&self, name: &str) -> PyResult<&PyAny> { + self.getattr(name)?.call0() + } + + /// Gets a member from the module. + /// + /// This is equivalent to the Python expression `module.name`. + #[deprecated(since = "0.14.0", note = "use getattr(name)?.call0() instead")] + pub fn get(&self, name: &str) -> PyResult<&PyAny> { + self.getattr(name) + } }