Skip to content

Commit

Permalink
Use $(;$generics)* instead of generics: <$(;$generics)+>
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu authored and davidhewitt committed Dec 18, 2020
1 parent f8d408f commit b341dff
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ pub use self::typeobject::PyType;
// Implementations core to all native types
#[macro_export]
macro_rules! pyobject_native_type_base(
($name: ty $(,generics: <$($generics:ident),+>)?) => {
unsafe impl<$($($generics),+)?> $crate::PyNativeType for $name {}
($name: ty $(;$generics: ident)* ) => {
unsafe impl<$($generics,)*> $crate::PyNativeType for $name {}

impl<$($($generics),+)?> ::std::fmt::Debug for $name {
impl<$($generics,)*> ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
Expand All @@ -42,7 +42,7 @@ macro_rules! pyobject_native_type_base(
}
}

impl<$($($generics),+)?> ::std::fmt::Display for $name {
impl<$($generics,)*> ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
Expand All @@ -51,7 +51,7 @@ macro_rules! pyobject_native_type_base(
}
}

impl<$($($generics),+)?> $crate::ToPyObject for $name
impl<$($generics,)*> $crate::ToPyObject for $name
{
#[inline]
fn to_object(&self, py: $crate::Python) -> $crate::PyObject {
Expand All @@ -60,7 +60,7 @@ macro_rules! pyobject_native_type_base(
}
}

impl<$($($generics),+)?> PartialEq for $name {
impl<$($generics,)*> PartialEq for $name {
#[inline]
fn eq(&self, o: &$name) -> bool {
use $crate::AsPyPointer;
Expand All @@ -75,17 +75,17 @@ macro_rules! pyobject_native_type_base(
// make sense on PyAny / have different implementations).
#[macro_export]
macro_rules! pyobject_native_type_named (
($name: ty $(,generics: <$($generics:ident),+>)?) => {
$crate::pyobject_native_type_base!($name $(,generics: <$($generics),+>)?);
($name: ty $(;$generics: ident)*) => {
$crate::pyobject_native_type_base!($name $(;$generics)*);

impl<$($($generics),+)?> ::std::convert::AsRef<$crate::PyAny> for $name {
impl<$($generics,)*> ::std::convert::AsRef<$crate::PyAny> for $name {
#[inline]
fn as_ref(&self) -> &$crate::PyAny {
&self.0
}
}

impl<$($($generics),+)?> ::std::ops::Deref for $name {
impl<$($generics,)*> ::std::ops::Deref for $name {
type Target = $crate::PyAny;

#[inline]
Expand All @@ -94,23 +94,23 @@ macro_rules! pyobject_native_type_named (
}
}

impl<$($($generics),+)?> $crate::AsPyPointer for $name {
impl<$($generics,)*> $crate::AsPyPointer for $name {
/// Gets the underlying FFI pointer, returns a borrowed pointer.
#[inline]
fn as_ptr(&self) -> *mut $crate::ffi::PyObject {
self.0.as_ptr()
}
}

impl<$($($generics),+)?> $crate::IntoPy<$crate::Py<$name>> for &'_ $name {
impl<$($generics,)*> $crate::IntoPy<$crate::Py<$name>> for &'_ $name {
#[inline]
fn into_py(self, py: $crate::Python) -> $crate::Py<$name> {
use $crate::AsPyPointer;
unsafe { $crate::Py::from_borrowed_ptr(py, self.as_ptr()) }
}
}

impl<$($($generics),+)?> From<&'_ $name> for $crate::Py<$name> {
impl<$($generics,)*> From<&'_ $name> for $crate::Py<$name> {
#[inline]
fn from(other: &$name) -> Self {
use $crate::AsPyPointer;
Expand All @@ -119,7 +119,7 @@ macro_rules! pyobject_native_type_named (
}
}

impl<'a, $($($generics),+)?> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
impl<'a, $($generics,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
fn from(ob: &'a $name) -> Self {
unsafe{&*(ob as *const $name as *const $crate::PyAny)}
}
Expand All @@ -129,21 +129,21 @@ macro_rules! pyobject_native_type_named (

#[macro_export]
macro_rules! pyobject_native_type_core {
($name: ty, $layout: path, $typeobject: expr, $module: expr $(, $checkfunction:path)? $(,generics: <$($generics:ident),+>)? ) => {
($name: ty, $layout: path, $typeobject: expr, $module: expr $(, $checkfunction:path)? $(;$generics: ident)*) => {
unsafe impl $crate::type_object::PyLayout<$name> for $layout {}
$crate::pyobject_native_type_named!($name $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_info!($name, $layout, $typeobject, $module $(, $checkfunction)? $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_extract!($name $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_named!($name $(;$generics)*);
$crate::pyobject_native_type_info!($name, $layout, $typeobject, $module $(, $checkfunction)? $(;$generics)*);
$crate::pyobject_native_type_extract!($name $(;$generics)*);
}
}

#[macro_export]
macro_rules! pyobject_native_type_sized {
($name: ty, $layout: path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $layout: path $(;$generics: ident)*) => {
// To prevent inheriting native types with ABI3
#[cfg(not(Py_LIMITED_API))]
impl $crate::type_object::PySizedLayout<$name> for $layout {}
impl<'a, $($($generics),+)?> $crate::derive_utils::PyBaseTypeUtils for $name {
impl<'a, $($generics,)*> $crate::derive_utils::PyBaseTypeUtils for $name {
type Dict = $crate::pyclass_slots::PyClassDummySlot;
type WeakRef = $crate::pyclass_slots::PyClassDummySlot;
type LayoutAsBase = $crate::pycell::PyCellBase<$name>;
Expand All @@ -155,26 +155,26 @@ macro_rules! pyobject_native_type_sized {

#[macro_export]
macro_rules! pyobject_native_type {
($name: ty, $layout: path, $typeobject: expr, $module: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
$crate::pyobject_native_type_core!($name, $layout, $typeobject, $module, $checkfunction $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_sized!($name, $layout $(,generics: <$($generics),+>)?);
($name: ty, $layout: path, $typeobject: expr, $module: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type_core!($name, $layout, $typeobject, $module, $checkfunction $(;$generics)*);
$crate::pyobject_native_type_sized!($name, $layout $(;$generics)*);
};
($name: ty, $layout: path, $typeobject: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $layout: path, $typeobject: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type! {
$name, $layout, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?
$name, $layout, $typeobject, Some("builtins"), $checkfunction $(;$generics)*
}
};
}

#[macro_export]
macro_rules! pyobject_native_var_type {
($name: ty, $typeobject: expr, $module: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $typeobject: expr, $module: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type_core!(
$name, $crate::ffi::PyObject, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?);
$name, $crate::ffi::PyObject, $typeobject, Some("builtins"), $checkfunction $(;$generics)*);
};
($name: ty, $typeobject: expr, $checkfunction: path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $typeobject: expr, $checkfunction: path $(;$generics: ident)*) => {
$crate::pyobject_native_var_type! {
$name, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?
$name, $typeobject, Some("builtins"), $checkfunction $(;$generics)*
}
};
}
Expand All @@ -183,8 +183,8 @@ macro_rules! pyobject_native_var_type {
// because rust-numpy has a special implementation.
#[macro_export]
macro_rules! pyobject_native_type_extract {
($name: ty $(,generics: <$($generics:ident),+>)?) => {
impl<'py, $($($generics),+)?> $crate::FromPyObject<'py> for &'py $name {
($name: ty $(;$generics: ident)*) => {
impl<'py, $($generics,)*> $crate::FromPyObject<'py> for &'py $name {
fn extract(obj: &'py $crate::PyAny) -> $crate::PyResult<Self> {
$crate::PyTryFrom::try_from(obj).map_err(Into::into)
}
Expand All @@ -195,8 +195,8 @@ macro_rules! pyobject_native_type_extract {
#[macro_export]
macro_rules! pyobject_native_type_info(
($name: ty, $layout: path, $typeobject: expr,
$module: expr $(, $checkfunction:path)? $(,generics: <$($generics:ident),+>)?) => {
unsafe impl<$($($generics),+)?> $crate::type_object::PyTypeInfo for $name {
$module: expr $(, $checkfunction:path)? $(;$generics: ident)*) => {
unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name {
type Type = ();
type BaseType = $crate::PyAny;
type Layout = $layout;
Expand Down

0 comments on commit b341dff

Please sign in to comment.