Less java-esque naming

This commit is contained in:
konstin 2018-08-26 18:41:55 +02:00
parent 6d9ee7fc38
commit 4847d56325
5 changed files with 49 additions and 56 deletions

View file

@ -11,7 +11,6 @@ categories = ["api-bindings", "development-tools::ffi"]
license = "Apache-2.0"
[dependencies]
log = "0.4.4"
quote = "0.6.6"
proc-macro2 = "0.4.13"

View file

@ -80,15 +80,15 @@ pub const OBJECT: Proto = Proto {
py_methods: &[
PyMethod {
name: "__format__",
proto: "::pyo3::class::basic::PyObjectFormatProtocolImpl",
proto: "::pyo3::class::basic::FormatProtocolImpl",
},
PyMethod {
name: "__bytes__",
proto: "::pyo3::class::basic::PyObjectBytesProtocolImpl",
proto: "::pyo3::class::basic::BytesProtocolImpl",
},
PyMethod {
name: "__unicode__",
proto: "::pyo3::class::basic::PyObjectUnicodeProtocolImpl",
proto: "::pyo3::class::basic::UnicodeProtocolImpl",
},
],
};

View file

@ -3,8 +3,6 @@
#![recursion_limit = "1024"]
#[macro_use]
extern crate log;
#[macro_use]
extern crate quote;
#[macro_use]

View file

@ -1,39 +1,35 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn;
use defs;
use func::impl_method_proto;
use method::FnSpec;
use proc_macro2::TokenStream;
use py_method;
use quote::ToTokens;
use syn;
pub fn build_py_proto(ast: &mut syn::ItemImpl) -> TokenStream {
if let Some((_, ref mut path, _)) = ast.trait_ {
let tokens = if let Some(ref mut segment) = path.segments.last() {
let ty = &ast.self_ty;
let items = &mut ast.items;
let proto = if let Some(ref mut segment) = path.segments.last() {
match segment.value().ident.to_string().as_str() {
"PyObjectProtocol" => impl_proto_impl(ty, items, &defs::OBJECT),
"PyAsyncProtocol" => impl_proto_impl(ty, items, &defs::ASYNC),
"PyMappingProtocol" => impl_proto_impl(ty, items, &defs::MAPPING),
"PyIterProtocol" => impl_proto_impl(ty, items, &defs::ITER),
"PyContextProtocol" => impl_proto_impl(ty, items, &defs::CONTEXT),
"PySequenceProtocol" => impl_proto_impl(ty, items, &defs::SEQ),
"PyNumberProtocol" => impl_proto_impl(ty, items, &defs::NUM),
"PyDescrProtocol" => impl_proto_impl(ty, items, &defs::DESCR),
"PyBufferProtocol" => impl_proto_impl(ty, items, &defs::BUFFER),
"PyGCProtocol" => impl_proto_impl(ty, items, &defs::GC),
_ => {
warn!("#[pyproto] can not be used with this block");
return TokenStream::new();
}
"PyObjectProtocol" => &defs::OBJECT,
"PyAsyncProtocol" => &defs::ASYNC,
"PyMappingProtocol" => &defs::MAPPING,
"PyIterProtocol" => &defs::ITER,
"PyContextProtocol" => &defs::CONTEXT,
"PySequenceProtocol" => &defs::SEQ,
"PyNumberProtocol" => &defs::NUM,
"PyDescrProtocol" => &defs::DESCR,
"PyBufferProtocol" => &defs::BUFFER,
"PyGCProtocol" => &defs::GC,
_ => panic!("#[pyproto] can not be used with this block"),
}
} else {
panic!("#[pyproto] can only be used with protocol trait implementations")
};
let tokens = impl_proto_impl(&ast.self_ty, &mut ast.items, proto);
// attach lifetime
let mut seg = path.segments.pop().unwrap().into_value();
seg.arguments = syn::PathArguments::AngleBracketed(parse_quote!{<'p>});

View file

@ -8,8 +8,8 @@
//! Parts of the documentation are copied from the respective methods from the
//! [typeobj docs](https://docs.python.org/3/c-api/typeobj.html)
use std;
use std::os::raw::c_int;
use std::ptr;
use callback::{BoolCallbackConverter, HashConverter, PyObjectCallbackConverter};
use class::methods::PyMethodDef;
@ -171,13 +171,13 @@ where
fn methods() -> Vec<PyMethodDef> {
let mut methods = Vec::new();
if let Some(def) = <Self as PyObjectFormatProtocolImpl>::__format__() {
if let Some(def) = <Self as FormatProtocolImpl>::__format__() {
methods.push(def)
}
if let Some(def) = <Self as PyObjectBytesProtocolImpl>::__bytes__() {
if let Some(def) = <Self as BytesProtocolImpl>::__bytes__() {
methods.push(def)
}
if let Some(def) = <Self as PyObjectUnicodeProtocolImpl>::__unicode__() {
if let Some(def) = <Self as UnicodeProtocolImpl>::__unicode__() {
methods.push(def)
}
methods
@ -195,15 +195,15 @@ where
}
}
trait PyObjectGetAttrProtocolImpl {
trait GetAttrProtocolImpl {
fn tp_getattro() -> Option<ffi::binaryfunc> {
None
}
}
impl<'p, T> PyObjectGetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<'p, T> GetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectGetAttrProtocolImpl for T
impl<T> GetAttrProtocolImpl for T
where
T: for<'p> PyObjectGetAttrProtocol<'p>,
{
@ -301,13 +301,13 @@ mod tp_setattro_impl {
}
}
trait PyObjectStrProtocolImpl {
trait StrProtocolImpl {
fn tp_str() -> Option<ffi::unaryfunc> {
None
}
}
impl<'p, T> PyObjectStrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectStrProtocolImpl for T
impl<'p, T> StrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> StrProtocolImpl for T
where
T: for<'p> PyObjectStrProtocol<'p>,
{
@ -321,13 +321,13 @@ where
}
}
trait PyObjectReprProtocolImpl {
trait ReprProtocolImpl {
fn tp_repr() -> Option<ffi::unaryfunc> {
None
}
}
impl<'p, T> PyObjectReprProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectReprProtocolImpl for T
impl<'p, T> ReprProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> ReprProtocolImpl for T
where
T: for<'p> PyObjectReprProtocol<'p>,
{
@ -342,36 +342,36 @@ where
}
#[doc(hidden)]
pub trait PyObjectFormatProtocolImpl {
pub trait FormatProtocolImpl {
fn __format__() -> Option<PyMethodDef> {
None
}
}
impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<'p, T> FormatProtocolImpl for T where T: PyObjectProtocol<'p> {}
#[doc(hidden)]
pub trait PyObjectBytesProtocolImpl {
pub trait BytesProtocolImpl {
fn __bytes__() -> Option<PyMethodDef> {
None
}
}
impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<'p, T> BytesProtocolImpl for T where T: PyObjectProtocol<'p> {}
#[doc(hidden)]
pub trait PyObjectUnicodeProtocolImpl {
pub trait UnicodeProtocolImpl {
fn __unicode__() -> Option<PyMethodDef> {
None
}
}
impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<'p, T> UnicodeProtocolImpl for T where T: PyObjectProtocol<'p> {}
trait PyObjectHashProtocolImpl {
trait HashProtocolImpl {
fn tp_hash() -> Option<ffi::hashfunc> {
None
}
}
impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectHashProtocolImpl for T
impl<'p, T> HashProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> HashProtocolImpl for T
where
T: for<'p> PyObjectHashProtocol<'p>,
{
@ -386,13 +386,13 @@ where
}
}
trait PyObjectBoolProtocolImpl {
trait BoolProtocolImpl {
fn nb_bool() -> Option<ffi::inquiry> {
None
}
}
impl<'p, T> PyObjectBoolProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectBoolProtocolImpl for T
impl<'p, T> BoolProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> BoolProtocolImpl for T
where
T: for<'p> PyObjectBoolProtocol<'p>,
{
@ -407,13 +407,13 @@ where
}
}
trait PyObjectRichcmpProtocolImpl {
trait RichcmpProtocolImpl {
fn tp_richcompare() -> Option<ffi::richcmpfunc> {
None
}
}
impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> PyObjectRichcmpProtocolImpl for T
impl<'p, T> RichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> RichcmpProtocolImpl for T
where
T: for<'p> PyObjectRichcmpProtocol<'p>,
{
@ -442,7 +442,7 @@ where
Ok(val) => val.into_object(py).into_ptr(),
Err(e) => {
e.restore(py);
std::ptr::null_mut()
ptr::null_mut()
}
}
}