mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Make the FromArgs derive less verbose
This commit is contained in:
27 files changed
+170
-180
No files matched your search
+15
-42
@@ -18,9 +18,9 @@ enum ParameterKind {
|
||||
impl ParameterKind {
|
||||
fn from_ident(ident: &Ident) -> Option<ParameterKind> {
|
||||
match ident.to_string().as_str() {
|
||||
"positional_only" => Some(ParameterKind::PositionalOnly),
|
||||
"positional_or_keyword" => Some(ParameterKind::PositionalOrKeyword),
|
||||
"keyword_only" => Some(ParameterKind::KeywordOnly),
|
||||
"positional" => Some(ParameterKind::PositionalOnly),
|
||||
"any" => Some(ParameterKind::PositionalOrKeyword),
|
||||
"named" => Some(ParameterKind::KeywordOnly),
|
||||
"flatten" => Some(ParameterKind::Flatten),
|
||||
_ => None,
|
||||
}
|
||||
@@ -29,9 +29,10 @@ impl ParameterKind {
|
||||
|
||||
struct ArgAttribute {
|
||||
kind: ParameterKind,
|
||||
default: Option<Expr>,
|
||||
optional: bool,
|
||||
default: Option<DefaultValue>,
|
||||
}
|
||||
// None == quote!(Default::default())
|
||||
type DefaultValue = Option<Expr>;
|
||||
|
||||
impl ArgAttribute {
|
||||
fn from_attribute(attr: &Attribute) -> Option<Result<ArgAttribute, Diagnostic>> {
|
||||
@@ -54,24 +55,19 @@ impl ArgAttribute {
|
||||
err_span!(
|
||||
first_arg,
|
||||
"The first argument to #[pyarg()] must be the parameter type, either \
|
||||
'positional_only', 'positional_or_keyword', 'keyword_only', or 'flatten'."
|
||||
'positional', 'any', 'named', or 'flatten'."
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut attribute = ArgAttribute {
|
||||
kind,
|
||||
default: None,
|
||||
optional: false,
|
||||
};
|
||||
|
||||
for arg in iter {
|
||||
attribute.parse_argument(arg)?;
|
||||
}
|
||||
|
||||
if attribute.default.is_some() && attribute.optional {
|
||||
bail_span!(attr, "Can't set both a default value and optional");
|
||||
}
|
||||
|
||||
Ok(attribute)
|
||||
}
|
||||
_ => bail_span!(attr, "pyarg must be a list, like #[pyarg(...)]"),
|
||||
@@ -85,43 +81,24 @@ impl ArgAttribute {
|
||||
}
|
||||
match arg {
|
||||
NestedMeta::Meta(Meta::Path(path)) => {
|
||||
if path_eq(&path, "default") {
|
||||
if self.default.is_some() {
|
||||
bail_span!(path, "Default already set");
|
||||
if path_eq(&path, "default") || path_eq(&path, "optional") {
|
||||
if self.default.is_none() {
|
||||
self.default = Some(None);
|
||||
}
|
||||
let expr = parse_quote!(Default::default());
|
||||
self.default = Some(expr);
|
||||
} else if path_eq(&path, "optional") {
|
||||
self.optional = true;
|
||||
} else {
|
||||
bail_span!(path, "Unrecognised pyarg attribute");
|
||||
}
|
||||
}
|
||||
NestedMeta::Meta(Meta::NameValue(name_value)) => {
|
||||
if path_eq(&name_value.path, "default") {
|
||||
if self.default.is_some() {
|
||||
if matches!(self.default, Some(Some(_))) {
|
||||
bail_span!(name_value, "Default already set");
|
||||
}
|
||||
|
||||
match name_value.lit {
|
||||
Lit::Str(ref val) => {
|
||||
let expr = val.parse::<Expr>().map_err(|_| {
|
||||
err_span!(val, "Expected a valid expression for default argument")
|
||||
})?;
|
||||
self.default = Some(expr);
|
||||
}
|
||||
Lit::Str(ref val) => self.default = Some(Some(val.parse()?)),
|
||||
_ => bail_span!(name_value, "Expected string value for default argument"),
|
||||
}
|
||||
} else if path_eq(&name_value.path, "optional") {
|
||||
match name_value.lit {
|
||||
Lit::Bool(ref val) => {
|
||||
self.optional = val.value;
|
||||
}
|
||||
_ => bail_span!(
|
||||
name_value.lit,
|
||||
"Expected boolean value for optional argument"
|
||||
),
|
||||
}
|
||||
} else {
|
||||
bail_span!(name_value, "Unrecognised pyarg attribute");
|
||||
}
|
||||
@@ -143,7 +120,6 @@ fn generate_field(field: &Field) -> Result<TokenStream2, Diagnostic> {
|
||||
ArgAttribute {
|
||||
kind: ParameterKind::PositionalOrKeyword,
|
||||
default: None,
|
||||
optional: false,
|
||||
}
|
||||
} else if pyarg_attrs.len() == 1 {
|
||||
pyarg_attrs.remove(0)
|
||||
@@ -168,21 +144,18 @@ fn generate_field(field: &Field) -> Result<TokenStream2, Diagnostic> {
|
||||
.map(|x| ::rustpython_vm::pyobject::TryFromObject::try_from_object(vm, x)).transpose()?
|
||||
};
|
||||
let ending = if let Some(default) = attr.default {
|
||||
let default = default.unwrap_or_else(|| parse_quote!(::std::default::Default::default()));
|
||||
quote! {
|
||||
.map(::rustpython_vm::function::FromArgOptional::from_inner)
|
||||
.unwrap_or_else(|| #default)
|
||||
}
|
||||
} else if attr.optional {
|
||||
quote! {
|
||||
.map(::rustpython_vm::function::OptionalArg::Present)
|
||||
.unwrap_or(::rustpython_vm::function::OptionalArg::Missing)
|
||||
}
|
||||
} else {
|
||||
let err = match attr.kind {
|
||||
ParameterKind::PositionalOnly | ParameterKind::PositionalOrKeyword => quote! {
|
||||
::rustpython_vm::function::ArgumentError::TooFewArgs
|
||||
},
|
||||
ParameterKind::KeywordOnly => quote! {
|
||||
::rustpython_vm::function::ArgumentError::RequiredKeywordArgument(tringify!(#name))
|
||||
::rustpython_vm::function::ArgumentError::RequiredKeywordArgument(stringify!(#name))
|
||||
},
|
||||
ParameterKind::Flatten => unreachable!(),
|
||||
};
|
||||
|
||||
+7
-7
@@ -15,9 +15,9 @@ where
|
||||
S: ?Sized + AnyStr<'a, E>,
|
||||
E: Copy,
|
||||
{
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
sep: Option<T>,
|
||||
#[pyarg(positional_or_keyword, default = "-1")]
|
||||
#[pyarg(any, default = "-1")]
|
||||
maxsplit: isize,
|
||||
_phantom1: std::marker::PhantomData<&'a S>,
|
||||
_phantom2: std::marker::PhantomData<E>,
|
||||
@@ -45,13 +45,13 @@ where
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct SplitLinesArgs {
|
||||
#[pyarg(positional_or_keyword, default = "false")]
|
||||
#[pyarg(any, default = "false")]
|
||||
pub keepends: bool,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct ExpandTabsArgs {
|
||||
#[pyarg(positional_or_keyword, default = "8")]
|
||||
#[pyarg(any, default = "8")]
|
||||
tabsize: isize,
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ impl ExpandTabsArgs {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct StartsEndsWithArgs {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
affix: PyObjectRef,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
start: Option<PyIntRef>,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
end: Option<PyIntRef>,
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -107,17 +107,17 @@ mod decl {
|
||||
#[derive(FromArgs)]
|
||||
#[allow(dead_code)]
|
||||
struct CompileArgs {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
source: Either<PyStrRef, PyBytesRef>,
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
filename: PyStrRef,
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
mode: PyStrRef,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
flags: OptionalArg<PyIntRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
dont_inherit: OptionalArg<bool>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
optimize: OptionalArg<PyIntRef>,
|
||||
}
|
||||
|
||||
@@ -188,10 +188,10 @@ mod decl {
|
||||
#[cfg(feature = "rustpython-compiler")]
|
||||
#[derive(FromArgs)]
|
||||
struct ScopeArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
globals: Option<PyDictRef>,
|
||||
// TODO: support any mapping for `locals`
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
locals: Option<PyDictRef>,
|
||||
}
|
||||
|
||||
@@ -669,13 +669,13 @@ mod decl {
|
||||
|
||||
#[derive(Debug, Default, FromArgs)]
|
||||
pub struct PrintOptions {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
sep: Option<PyStrRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
end: Option<PyStrRef>,
|
||||
#[pyarg(keyword_only, default = "IntoPyBool::FALSE")]
|
||||
#[pyarg(named, default = "IntoPyBool::FALSE")]
|
||||
flush: IntoPyBool,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
file: Option<PyObjectRef>,
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -64,11 +64,11 @@ impl TryFromObject for PyBytesInner {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct ByteInnerNewOptions {
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
source: OptionalArg<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
encoding: OptionalArg<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
errors: OptionalArg<PyStrRef>,
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ impl ByteInnerNewOptions {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct ByteInnerFindOptions {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
sub: Either<PyBytesInner, PyIntRef>,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
start: Option<PyIntRef>,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
end: Option<PyIntRef>,
|
||||
}
|
||||
|
||||
@@ -180,9 +180,9 @@ impl ByteInnerFindOptions {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct ByteInnerPaddingOptions {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
width: isize,
|
||||
#[pyarg(positional_only, optional = true)]
|
||||
#[pyarg(positional, optional)]
|
||||
fillchar: OptionalArg<PyObjectRef>,
|
||||
}
|
||||
|
||||
@@ -207,9 +207,9 @@ impl ByteInnerPaddingOptions {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct ByteInnerTranslateOptions {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
table: Either<PyBytesInner, PyNoneRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
delete: OptionalArg<PyBytesInner>,
|
||||
}
|
||||
|
||||
@@ -1190,9 +1190,9 @@ impl<'s> AnyStr<'s, u8> for [u8] {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct DecodeArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
encoding: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
errors: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -244,6 +244,23 @@ pub trait FromArgs: Sized {
|
||||
fn from_args(vm: &VirtualMachine, args: &mut PyFuncArgs) -> Result<Self, ArgumentError>;
|
||||
}
|
||||
|
||||
pub trait FromArgOptional {
|
||||
type Inner: TryFromObject;
|
||||
fn from_inner(x: Self::Inner) -> Self;
|
||||
}
|
||||
impl<T: TryFromObject> FromArgOptional for OptionalArg<T> {
|
||||
type Inner = T;
|
||||
fn from_inner(x: T) -> Self {
|
||||
Self::Present(x)
|
||||
}
|
||||
}
|
||||
impl<T: TryFromObject> FromArgOptional for T {
|
||||
type Inner = Self;
|
||||
fn from_inner(x: Self) -> Self {
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
/// A map of keyword arguments to their values.
|
||||
///
|
||||
/// A built-in function with a `KwArgs` parameter is analagous to a Python
|
||||
|
||||
@@ -308,9 +308,9 @@ impl Hashable for PyComplex {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct ComplexArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
real: Option<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
imag: Option<PyObjectRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -691,29 +691,29 @@ impl Hashable for PyInt {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct IntOptions {
|
||||
#[pyarg(positional_only, optional = true)]
|
||||
#[pyarg(positional, optional)]
|
||||
val_options: OptionalArg<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
base: OptionalArg<PyObjectRef>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct IntFromByteArgs {
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
bytes: PyBytesInner,
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
byteorder: PyStrRef,
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
signed: OptionalArg<IntoPyBool>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct IntToByteArgs {
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
length: PyIntRef,
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
byteorder: PyStrRef,
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
signed: OptionalArg<IntoPyBool>,
|
||||
}
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ impl PyList {
|
||||
|
||||
#[derive(FromArgs, Default)]
|
||||
pub(crate) struct SortOptions {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
key: Option<PyObjectRef>,
|
||||
#[pyarg(keyword_only, default = "false")]
|
||||
#[pyarg(named, default = "false")]
|
||||
reverse: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,13 @@ pub type PyPropertyRef = PyRef<PyProperty>;
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct PropertyArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
fget: Option<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
fset: Option<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
fdel: Option<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
doc: Option<PyObjectRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -168,11 +168,11 @@ impl PyStringReverseIterator {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct StrArgs {
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
object: OptionalArg<PyObjectRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
encoding: OptionalArg<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
errors: OptionalArg<PyStrRef>,
|
||||
}
|
||||
|
||||
@@ -1072,9 +1072,9 @@ impl Comparable for PyStr {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct EncodeArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
encoding: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
errors: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
@@ -1141,11 +1141,11 @@ type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef, str, char>;
|
||||
|
||||
#[derive(FromArgs)]
|
||||
pub struct FindArgs {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
sub: PyStrRef,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
start: Option<PyIntRef>,
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
end: Option<PyIntRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ mod decl {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct NewlineArg {
|
||||
#[pyarg(keyword_only, default = "true")]
|
||||
#[pyarg(named, default = "true")]
|
||||
newline: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ mod _collections {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct PyDequeOptions {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
maxlen: Option<usize>,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ mod decl {
|
||||
#[derive(FromArgs)]
|
||||
#[allow(unused)]
|
||||
struct EnableArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
file: Option<i64>,
|
||||
#[pyarg(positional_or_keyword, default = "true")]
|
||||
#[pyarg(any, default = "true")]
|
||||
all_threads: bool,
|
||||
}
|
||||
|
||||
@@ -45,13 +45,13 @@ mod decl {
|
||||
#[derive(FromArgs)]
|
||||
#[allow(unused)]
|
||||
struct RegisterArgs {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
signum: i64,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
file: Option<i64>,
|
||||
#[pyarg(positional_or_keyword, default = "true")]
|
||||
#[pyarg(any, default = "true")]
|
||||
all_threads: bool,
|
||||
#[pyarg(positional_or_keyword, default = "false")]
|
||||
#[pyarg(any, default = "false")]
|
||||
chain: bool,
|
||||
}
|
||||
|
||||
|
||||
+16
-16
@@ -38,7 +38,7 @@ mod _io {
|
||||
pub(super) struct OptionalSize {
|
||||
// In a few functions, the default value is -1 rather than None.
|
||||
// Make sure the default value doesn't affect compatibility.
|
||||
#[pyarg(positional_only, default = "None")]
|
||||
#[pyarg(positional, default)]
|
||||
size: Option<isize>,
|
||||
}
|
||||
|
||||
@@ -607,13 +607,13 @@ mod _io {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct TextIOWrapperArgs {
|
||||
#[pyarg(positional_or_keyword, optional = false)]
|
||||
#[pyarg(any)]
|
||||
buffer: PyObjectRef,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
encoding: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
errors: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
newline: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
@@ -795,7 +795,7 @@ mod _io {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct StringIOArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
#[allow(dead_code)]
|
||||
// TODO: use this
|
||||
newline: Option<PyStrRef>,
|
||||
@@ -1133,17 +1133,17 @@ mod _io {
|
||||
#[derive(FromArgs)]
|
||||
#[allow(unused)]
|
||||
pub struct OpenArgs {
|
||||
#[pyarg(positional_or_keyword, default = "-1")]
|
||||
#[pyarg(any, default = "-1")]
|
||||
buffering: isize,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
encoding: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
errors: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
newline: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "true")]
|
||||
#[pyarg(any, default = "true")]
|
||||
closefd: bool,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
opener: Option<PyObjectRef>,
|
||||
}
|
||||
impl Default for OpenArgs {
|
||||
@@ -1450,13 +1450,13 @@ mod fileio {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct FileIOArgs {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
name: Either<PyStrRef, i64>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
mode: Option<PyStrRef>,
|
||||
#[pyarg(positional_or_keyword, default = "true")]
|
||||
#[pyarg(any, default = "true")]
|
||||
closefd: bool,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
opener: Option<PyObjectRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -547,7 +547,7 @@ mod decl {
|
||||
#[derive(FromArgs)]
|
||||
struct GroupByArgs {
|
||||
iterable: PyObjectRef,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
key: OptionalOption<PyObjectRef>,
|
||||
}
|
||||
|
||||
@@ -1044,7 +1044,7 @@ mod decl {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct ProductArgs {
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
repeat: OptionalArg<usize>,
|
||||
}
|
||||
|
||||
@@ -1485,7 +1485,7 @@ mod decl {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct ZiplongestArgs {
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
fillvalue: OptionalArg<PyObjectRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -47,13 +47,13 @@ make_math_func_bool!(math_isnan, is_nan);
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct IsCloseArgs {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
a: IntoPyFloat,
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
b: IntoPyFloat,
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
rel_tol: OptionalArg<IntoPyFloat>,
|
||||
#[pyarg(keyword_only, optional = true)]
|
||||
#[pyarg(named, optional)]
|
||||
abs_tol: OptionalArg<IntoPyFloat>,
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -198,19 +198,19 @@ pub fn errno_err(vm: &VirtualMachine) -> PyBaseExceptionRef {
|
||||
#[allow(dead_code)]
|
||||
#[derive(FromArgs, Default)]
|
||||
pub struct TargetIsDirectory {
|
||||
#[pyarg(keyword_only, default = "false")]
|
||||
#[pyarg(named, default = "false")]
|
||||
target_is_directory: bool,
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Default)]
|
||||
pub struct DirFd {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
dir_fd: Option<PyIntRef>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct FollowSymlinks {
|
||||
#[pyarg(keyword_only, default = "true")]
|
||||
#[pyarg(named, default = "true")]
|
||||
follow_symlinks: bool,
|
||||
}
|
||||
|
||||
@@ -769,11 +769,11 @@ mod _os {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct UtimeArgs {
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
path: PyPathLike,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
times: Option<PyTupleRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
ns: Option<PyTupleRef>,
|
||||
#[pyarg(flatten)]
|
||||
_dir_fd: DirFd,
|
||||
@@ -1913,15 +1913,15 @@ mod posix {
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
#[derive(FromArgs)]
|
||||
pub(super) struct PosixSpawnArgs {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
path: PyPathLike,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
args: PyIterable<PyPathLike>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
env: PyMapping,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
file_actions: Option<PyIterable<PyTupleRef>>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
setsigdef: Option<PyIterable<i32>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ macro_rules! gen_args {
|
||||
($($field:ident: $t:ty),*$(,)?) => {
|
||||
#[derive(FromArgs)]
|
||||
struct ForkExecArgs {
|
||||
$(#[pyarg(positional_only)] $field: $t,)*
|
||||
$(#[pyarg(positional)] $field: $t,)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -769,7 +769,7 @@ mod _struct {
|
||||
#[derive(FromArgs)]
|
||||
struct UpdateFromArgs {
|
||||
buffer: PyBytesLike,
|
||||
#[pyarg(positional_or_keyword, default = "0")]
|
||||
#[pyarg(any, default = "0")]
|
||||
offset: isize,
|
||||
}
|
||||
|
||||
|
||||
@@ -500,18 +500,18 @@ fn socket_inet_ntoa(packed_ip: PyBytesRef, vm: &VirtualMachine) -> PyResult {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct GAIOptions {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
host: Option<PyStrRef>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
port: Option<Either<PyStrRef, i32>>,
|
||||
|
||||
#[pyarg(positional_only, default = "0")]
|
||||
#[pyarg(positional, default = "0")]
|
||||
family: i32,
|
||||
#[pyarg(positional_only, default = "0")]
|
||||
#[pyarg(positional, default = "0")]
|
||||
ty: i32,
|
||||
#[pyarg(positional_only, default = "0")]
|
||||
#[pyarg(positional, default = "0")]
|
||||
proto: i32,
|
||||
#[pyarg(positional_only, default = "0")]
|
||||
#[pyarg(positional, default = "0")]
|
||||
flags: i32,
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -153,9 +153,9 @@ fn ssl_enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult<
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct Txt2ObjArgs {
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
txt: CString,
|
||||
#[pyarg(positional_or_keyword, default = "false")]
|
||||
#[pyarg(any, default = "false")]
|
||||
name: bool,
|
||||
}
|
||||
fn ssl_txt2obj(args: Txt2ObjArgs, vm: &VirtualMachine) -> PyResult<PyNid> {
|
||||
@@ -482,25 +482,25 @@ impl PySslContext {
|
||||
#[derive(FromArgs)]
|
||||
// #[allow(dead_code)]
|
||||
struct WrapSocketArgs {
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
sock: PySocketRef,
|
||||
#[pyarg(positional_or_keyword)]
|
||||
#[pyarg(any)]
|
||||
server_side: bool,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
server_hostname: Option<PyStrRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
owner: Option<PyObjectRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
session: Option<PyObjectRef>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct LoadVerifyLocationsArgs {
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
cafile: Option<CString>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
capath: Option<CString>,
|
||||
#[pyarg(positional_or_keyword, default = "None")]
|
||||
#[pyarg(any, default)]
|
||||
cadata: Option<Either<PyStrRef, PyBytesLike>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ const TIMEOUT_MAX: f64 = (PY_TIMEOUT_MAX / 1_000_000) as f64;
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct AcquireArgs {
|
||||
#[pyarg(positional_or_keyword, default = "true")]
|
||||
#[pyarg(any, default = "true")]
|
||||
blocking: bool,
|
||||
#[pyarg(positional_or_keyword, default = "Either::A(-1.0)")]
|
||||
#[pyarg(any, default = "Either::A(-1.0)")]
|
||||
timeout: Either<f64, i64>,
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ mod _warnings {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct WarnArgs {
|
||||
#[pyarg(positional_only, optional = false)]
|
||||
#[pyarg(positional)]
|
||||
message: PyStrRef,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
category: OptionalArg<PyTypeRef>,
|
||||
#[pyarg(positional_or_keyword, optional = true)]
|
||||
#[pyarg(any, optional)]
|
||||
stacklevel: OptionalArg<u32>,
|
||||
}
|
||||
|
||||
|
||||
@@ -106,23 +106,23 @@ fn _winapi_GetFileType(h: usize, vm: &VirtualMachine) -> PyResult<u32> {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct CreateProcessArgs {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
name: Option<PyStrRef>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
command_line: Option<PyStrRef>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
_proc_attrs: PyObjectRef,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
_thread_attrs: PyObjectRef,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
inherit_handles: i32,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
creation_flags: u32,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
env_mapping: Option<PyMapping>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
current_dir: Option<PyStrRef>,
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
startup_info: PyObjectRef,
|
||||
}
|
||||
|
||||
|
||||
@@ -332,9 +332,9 @@ mod decl {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct DecompressArgs {
|
||||
#[pyarg(positional_only)]
|
||||
#[pyarg(positional)]
|
||||
data: PyBytesRef,
|
||||
#[pyarg(positional_or_keyword, default = "0")]
|
||||
#[pyarg(any, default = "0")]
|
||||
max_length: usize,
|
||||
}
|
||||
|
||||
|
||||
@@ -42,15 +42,15 @@ impl FetchResponseFormat {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct FetchArgs {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
response_format: Option<PyStrRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
method: Option<PyStrRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
headers: Option<PyDictRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
body: Option<PyObjectRef>,
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
content_type: Option<PyStrRef>,
|
||||
}
|
||||
|
||||
|
||||
@@ -231,13 +231,13 @@ impl PyJsValue {
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct CallOptions {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
this: Option<PyJsValueRef>,
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
struct NewObjectOptions {
|
||||
#[pyarg(keyword_only, default = "None")]
|
||||
#[pyarg(named, default)]
|
||||
prototype: Option<PyJsValueRef>,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user