Skip to content

Commit a5b76bc

Browse files
committed
pyo3_path, part 4: rename to crate to keep consistent with serde
1 parent 681217d commit a5b76bc

File tree

14 files changed

+26
-27
lines changed

14 files changed

+26
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
- Add `Py::setattr` method. [#2009](https://github.com/PyO3/pyo3/pull/2009)
2323
- Add `PyCapsule`, exposing the [Capsule API](https://docs.python.org/3/c-api/capsule.html#capsules). [#1980](https://github.com/PyO3/pyo3/pull/1980)
24-
- All PyO3 proc-macros except the deprecated `#[pyproto]` now accept a supplemental attribute `#[pyo3(pyo3_path = "some::path")]` that specifies
24+
- All PyO3 proc-macros except the deprecated `#[pyproto]` now accept a supplemental attribute `#[pyo3(crate = "some::path")]` that specifies
2525
where to find the `pyo3` crate, in case it has been renamed or is re-exported and not found at the crate root. [#2022](https://github.com/PyO3/pyo3/pull/2022)
2626

2727
### Changed

guide/src/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ crate.
149149

150150
However, when the dependency is renamed, or your crate only indirectly depends
151151
on `pyo3`, you need to let the macro code know where to find the crate. This is
152-
done with the `pyo3_path` attribute:
152+
done with the `crate` attribute:
153153

154154
```rust
155155
# use pyo3::prelude::*;
156156
# pub extern crate pyo3;
157157
# mod reexported { pub use ::pyo3; }
158158
#[pyclass]
159-
#[pyo3(pyo3_path = "reexported::pyo3")]
159+
#[pyo3(crate = "reexported::pyo3")]
160160
struct MyClass;
161161
```

pyo3-macros-backend/src/attributes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod kw {
1717
syn::custom_keyword!(signature);
1818
syn::custom_keyword!(text_signature);
1919
syn::custom_keyword!(transparent);
20-
syn::custom_keyword!(pyo3_path);
2120
}
2221

2322
#[derive(Clone, Debug, PartialEq)]
@@ -50,7 +49,7 @@ pub struct PyO3PathAttribute(pub Path);
5049

5150
impl Parse for PyO3PathAttribute {
5251
fn parse(input: ParseStream) -> Result<Self> {
53-
let _: kw::pyo3_path = input.parse()?;
52+
let _: Token![crate] = input.parse()?;
5453
let _: Token![=] = input.parse()?;
5554
let string_literal: LitStr = input.parse()?;
5655
string_literal.parse().map(PyO3PathAttribute)

pyo3-macros-backend/src/from_pyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl Parse for ContainerPyO3Attribute {
334334
let _: attributes::kw::annotation = input.parse()?;
335335
let _: Token![=] = input.parse()?;
336336
input.parse().map(ContainerPyO3Attribute::ErrorAnnotation)
337-
} else if lookahead.peek(attributes::kw::pyo3_path) {
337+
} else if lookahead.peek(Token![crate]) {
338338
input.parse().map(ContainerPyO3Attribute::PyO3Path)
339339
} else {
340340
Err(lookahead.error())

pyo3-macros-backend/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Parse for PyModulePyO3Option {
170170
let lookahead = input.lookahead1();
171171
if lookahead.peek(attributes::kw::name) {
172172
input.parse().map(PyModulePyO3Option::Name)
173-
} else if lookahead.peek(attributes::kw::pyo3_path) {
173+
} else if lookahead.peek(syn::Token![crate]) {
174174
input.parse().map(PyModulePyO3Option::PyO3Path)
175175
} else {
176176
Err(lookahead.error())

pyo3-macros-backend/src/pyclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Parse for PyClassPyO3Option {
201201
let lookahead = input.lookahead1();
202202
if lookahead.peek(attributes::kw::text_signature) {
203203
input.parse().map(PyClassPyO3Option::TextSignature)
204-
} else if lookahead.peek(attributes::kw::pyo3_path) {
204+
} else if lookahead.peek(Token![crate]) {
205205
input.parse().map(PyClassPyO3Option::PyO3Path)
206206
} else {
207207
Err(lookahead.error())

pyo3-macros-backend/src/pyfunction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl Parse for PyFunctionOptions {
257257
if !input.is_empty() {
258258
let _: Comma = input.parse()?;
259259
}
260-
} else if lookahead.peek(attributes::kw::pyo3_path) {
260+
} else if lookahead.peek(syn::Token![crate]) {
261261
// TODO needs duplicate check?
262262
options.pyo3_path = Some(input.parse()?);
263263
} else {
@@ -292,7 +292,7 @@ impl Parse for PyFunctionOption {
292292
input.parse().map(PyFunctionOption::Signature)
293293
} else if lookahead.peek(attributes::kw::text_signature) {
294294
input.parse().map(PyFunctionOption::TextSignature)
295-
} else if lookahead.peek(attributes::kw::pyo3_path) {
295+
} else if lookahead.peek(syn::Token![crate]) {
296296
input.parse().map(PyFunctionOption::PyO3Path)
297297
} else {
298298
Err(lookahead.error())

pyo3-macros-backend/src/pyimpl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::collections::HashSet;
44

55
use crate::{
6-
attributes::{self, take_pyo3_options, PyO3PathAttribute},
6+
attributes::{take_pyo3_options, PyO3PathAttribute},
77
konst::{ConstAttributes, ConstSpec},
88
pyfunction::PyFunctionOptions,
99
pymethod::{self, is_proto_method},
@@ -32,7 +32,7 @@ enum PyImplPyO3Option {
3232
impl Parse for PyImplPyO3Option {
3333
fn parse(input: ParseStream) -> Result<Self> {
3434
let lookahead = input.lookahead1();
35-
if lookahead.peek(attributes::kw::pyo3_path) {
35+
if lookahead.peek(syn::Token![crate]) {
3636
input.parse().map(PyImplPyO3Option::PyO3Path)
3737
} else {
3838
Err(lookahead.error())

src/test_hygiene/misc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#![no_implicit_prelude]
22

33
#[derive(crate::FromPyObject)]
4-
#[pyo3(pyo3_path = "crate")]
4+
#[pyo3(crate = "crate")]
55
struct Derive1(i32); // newtype case
66

77
#[derive(crate::FromPyObject)]
8-
#[pyo3(pyo3_path = "crate")]
8+
#[pyo3(crate = "crate")]
99
#[allow(dead_code)]
1010
struct Derive2(i32, i32); // tuple case
1111

1212
#[derive(crate::FromPyObject)]
13-
#[pyo3(pyo3_path = "crate")]
13+
#[pyo3(crate = "crate")]
1414
#[allow(dead_code)]
1515
struct Derive3 {
1616
f: i32,
1717
g: i32,
1818
} // struct case
1919

2020
#[derive(crate::FromPyObject)]
21-
#[pyo3(pyo3_path = "crate")]
21+
#[pyo3(crate = "crate")]
2222
#[allow(dead_code)]
2323
enum Derive4 {
2424
A(i32),

src/test_hygiene/pyclass.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#![allow(unused_variables)]
33

44
#[crate::pyclass]
5-
#[pyo3(pyo3_path = "crate")]
5+
#[pyo3(crate = "crate")]
66
#[derive(::std::clone::Clone)]
77
pub struct Foo;
88

99
#[crate::pyclass]
10-
#[pyo3(pyo3_path = "crate")]
10+
#[pyo3(crate = "crate")]
1111
pub struct Foo2;
1212

1313
#[crate::pyclass(
@@ -19,7 +19,7 @@ pub struct Foo2;
1919
extends = crate::types::PyAny,
2020
module = "Spam"
2121
)]
22-
#[pyo3(pyo3_path = "crate")]
22+
#[pyo3(crate = "crate")]
2323
pub struct Bar {
2424
#[pyo3(get, set)]
2525
a: u8,

0 commit comments

Comments
 (0)