Skip to content

Commit 3d5d3fd

Browse files
authored
Merge pull request RustPython#3759 from youknowone/pyimpl
pyimpl -> pyclass
2 parents 13acb1c + 055c5cf commit 3d5d3fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+311
-313
lines changed

derive/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ pub fn pyclass(
4545
) -> proc_macro::TokenStream {
4646
let attr = parse_macro_input!(attr as AttributeArgs);
4747
let item = parse_macro_input!(item as Item);
48-
result_to_tokens(pyclass::impl_pyclass(attr, item))
48+
if matches!(item, syn::Item::Impl(_) | syn::Item::Trait(_)) {
49+
result_to_tokens(pyclass::impl_pyimpl(attr, item))
50+
} else {
51+
result_to_tokens(pyclass::impl_pyclass(attr, item))
52+
}
4953
}
5054

5155
/// This macro serves a goal of generating multiple
@@ -76,16 +80,6 @@ pub fn pyexception(
7680
result_to_tokens(pyclass::impl_pyexception(attr, item))
7781
}
7882

79-
#[proc_macro_attribute]
80-
pub fn pyimpl(
81-
attr: proc_macro::TokenStream,
82-
item: proc_macro::TokenStream,
83-
) -> proc_macro::TokenStream {
84-
let attr = parse_macro_input!(attr as AttributeArgs);
85-
let item = parse_macro_input!(item as Item);
86-
result_to_tokens(pyclass::impl_pyimpl(attr, item))
87-
}
88-
8983
#[proc_macro_attribute]
9084
pub fn pymodule(
9185
attr: proc_macro::TokenStream,

derive/src/pyclass.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
373373
}
374374
}
375375

376-
#[pyimpl(flags(BASETYPE, HAS_DICT))]
376+
#[pyclass(flags(BASETYPE, HAS_DICT))]
377377
impl #class_name {
378378
#[pyslot]
379379
pub(crate) fn slot_new(
@@ -959,7 +959,7 @@ fn extract_impl_attrs(attr: AttributeArgs, item: &Ident) -> Result<ExtractedImpl
959959
let path = match meta {
960960
NestedMeta::Meta(Meta::Path(path)) => path,
961961
meta => {
962-
bail_span!(meta, "#[pyimpl(with(...))] arguments should be paths")
962+
bail_span!(meta, "#[pyclass(with(...))] arguments should be paths")
963963
}
964964
};
965965
let (extend_class, extend_slots) = if path_eq(&path, "PyRef") {
@@ -993,12 +993,12 @@ fn extract_impl_attrs(attr: AttributeArgs, item: &Ident) -> Result<ExtractedImpl
993993
} else {
994994
bail_span!(
995995
path,
996-
"#[pyimpl(flags(...))] arguments should be ident"
996+
"#[pyclass(flags(...))] arguments should be ident"
997997
)
998998
}
999999
}
10001000
meta => {
1001-
bail_span!(meta, "#[pyimpl(flags(...))] arguments should be ident")
1001+
bail_span!(meta, "#[pyclass(flags(...))] arguments should be ident")
10021002
}
10031003
}
10041004
}
@@ -1098,7 +1098,7 @@ where
10981098
if ALL_ALLOWED_NAMES.contains(&attr_name.as_str()) {
10991099
return Err(syn::Error::new_spanned(
11001100
attr,
1101-
format!("#[pyimpl] doesn't accept #[{}]", wrong_name),
1101+
format!("#[pyclass] doesn't accept #[{}]", wrong_name),
11021102
));
11031103
} else {
11041104
continue;

derive/src/pymodule.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ pub fn impl_pymodule(attr: AttributeArgs, module_item: Item) -> Result<TokenStre
6969

7070
// collect to context
7171
for item in items.iter_mut() {
72+
if matches!(item, Item::Impl(_) | Item::Trait(_)) {
73+
// #[pyclass] implementations
74+
continue;
75+
}
7276
let r = item.try_split_attr_mut(|attrs, item| {
7377
let (pyitems, cfgs) = attrs_to_module_items(attrs, module_item_new)?;
7478
for pyitem in pyitems.iter().rev() {

stdlib/src/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ mod array {
673673
}
674674
}
675675

676-
#[pyimpl(
676+
#[pyclass(
677677
flags(BASETYPE),
678678
with(Comparable, AsBuffer, AsMapping, Iterable, Constructor)
679679
)]
@@ -1293,7 +1293,7 @@ mod array {
12931293
internal: PyMutex<PositionIterInternal<PyArrayRef>>,
12941294
}
12951295

1296-
#[pyimpl(with(IterNext), flags(HAS_DICT))]
1296+
#[pyclass(with(IterNext), flags(HAS_DICT))]
12971297
impl PyArrayIter {
12981298
#[pymethod(magic)]
12991299
fn setstate(&self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

stdlib/src/contextvars.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod _contextvars {
1414
#[derive(Debug, PyPayload)]
1515
struct PyContext {} // not to confuse with vm::Context
1616

17-
#[pyimpl(with(Initializer))]
17+
#[pyclass(with(Initializer))]
1818
impl PyContext {
1919
#[pymethod]
2020
fn run(
@@ -99,7 +99,7 @@ mod _contextvars {
9999
default: OptionalArg<PyObjectRef>,
100100
}
101101

102-
#[pyimpl(with(Initializer))]
102+
#[pyclass(with(Initializer))]
103103
impl ContextVar {
104104
#[pyproperty]
105105
fn name(&self) -> String {
@@ -172,7 +172,7 @@ mod _contextvars {
172172
old_value: PyObjectRef,
173173
}
174174

175-
#[pyimpl(with(Initializer))]
175+
#[pyclass(with(Initializer))]
176176
impl ContextToken {
177177
#[pyproperty]
178178
fn var(&self, _vm: &VirtualMachine) -> PyObjectRef {

stdlib/src/csv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ mod _csv {
165165
}
166166
}
167167

168-
#[pyimpl(with(IterNext))]
168+
#[pyclass(with(IterNext))]
169169
impl Reader {}
170170
impl IterNextIterable for Reader {}
171171
impl IterNext for Reader {
@@ -255,7 +255,7 @@ mod _csv {
255255
}
256256
}
257257

258-
#[pyimpl]
258+
#[pyclass]
259259
impl Writer {
260260
#[pymethod]
261261
fn writerow(&self, row: PyObjectRef, vm: &VirtualMachine) -> PyResult {

stdlib/src/grp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod grp {
2121
gr_gid: u32,
2222
gr_mem: PyListRef,
2323
}
24-
#[pyimpl(with(PyStructSequence))]
24+
#[pyclass(with(PyStructSequence))]
2525
impl Group {
2626
fn from_unistd_group(group: unistd::Group, vm: &VirtualMachine) -> Self {
2727
let cstr_lossy = |s: std::ffi::CString| {

stdlib/src/hashlib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod hashlib {
5858
}
5959
}
6060

61-
#[pyimpl]
61+
#[pyclass]
6262
impl PyHasher {
6363
fn new(name: &str, d: HashWrapper) -> Self {
6464
PyHasher {

stdlib/src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod _json {
6464
}
6565
}
6666

67-
#[pyimpl(with(Callable, Constructor))]
67+
#[pyclass(with(Callable, Constructor))]
6868
impl JsonScanner {
6969
fn parse(
7070
&self,

stdlib/src/mmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ mod mmap {
458458
};
459459
}
460460

461-
#[pyimpl(with(Constructor, AsMapping, AsSequence, AsBuffer), flags(BASETYPE))]
461+
#[pyclass(with(Constructor, AsMapping, AsSequence, AsBuffer), flags(BASETYPE))]
462462
impl PyMmap {
463463
fn as_bytes_mut(&self) -> BorrowedValueMut<[u8]> {
464464
PyMutexGuard::map(self.mmap.lock(), |m| {

0 commit comments

Comments
 (0)