File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,14 +68,28 @@ impl Class {
6868 NestedMeta :: Meta ( meta) => meta,
6969 NestedMeta :: Lit ( _) => continue ,
7070 } ;
71- if let Meta :: NameValue ( name_value) = meta {
72- if path_eq ( & name_value. path , "name" ) {
73- if let Lit :: Str ( s) = & name_value. lit {
74- py_name = Some ( s. value ( ) ) ;
71+
72+ match meta {
73+ Meta :: NameValue ( name_value) => {
74+ if path_eq ( & name_value. path , "name" ) {
75+ if let Lit :: Str ( s) = & name_value. lit {
76+ py_name = Some ( s. value ( ) ) ;
77+ } else {
78+ bail_span ! ( & sig. ident, "#[pymethod(name = ...)] must be a string" ) ;
79+ }
80+ }
81+ }
82+ Meta :: Path ( path) => {
83+ if path. get_ident ( ) . map_or ( false , |v| v == "magic" ) {
84+ py_name = Some ( format ! ( "__{}__" , sig. ident. to_string( ) ) ) ;
7585 } else {
76- bail_span ! ( & sig. ident, "#[pymethod(name = ...)] must be a string" ) ;
86+ bail_span ! (
87+ & sig. ident,
88+ "#[pymethod(magic)] or #[pymethod(name = ...)] is expected"
89+ ) ;
7790 }
7891 }
92+ _ => ( ) ,
7993 }
8094 }
8195
Original file line number Diff line number Diff line change @@ -242,7 +242,7 @@ impl PyValue for PyFunction {
242242
243243#[ pyimpl( with( PyBuiltinDescriptor ) ) ]
244244impl PyFunction {
245- #[ pymethod( name = "__call__" ) ]
245+ #[ pymethod( magic ) ]
246246 fn call ( zelf : PyObjectRef , args : PyFuncArgs , vm : & VirtualMachine ) -> PyResult {
247247 vm. invoke ( & zelf, args)
248248 }
You can’t perform that action at this time.
0 commit comments