-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix decorators #3783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix decorators #3783
Conversation
|
|
|
related to #3742 |
a77ae32 to
f2e62cf
Compare
vm/src/builtins/classmethod.rs
Outdated
|
|
||
| fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult { | ||
| PyClassMethod { | ||
| let _callable = callable.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually _ prefix means unused variable.
vm/src/builtins/classmethod.rs
Outdated
| match obj.set_attr("__doc__", doc, vm) { | ||
| Err(e) => Err(e), | ||
| Ok(_) => result, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| match obj.set_attr("__doc__", doc, vm) { | |
| Err(e) => Err(e), | |
| Ok(_) => result, | |
| } | |
| obj.set_attr("__doc__", doc, vm)?; | |
| result |
vm/src/builtins/staticmethod.rs
Outdated
|
|
||
| fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult { | ||
| PyStaticMethod { callable } | ||
| let _callable = callable.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is another _callable
|
Good points. I will change the codes. |
vm/src/builtins/classmethod.rs
Outdated
| let _descr_get: PyResult<PyObjectRef> = zelf.callable.lock().get_attr("__get__", vm); | ||
| match _descr_get { | ||
| Err(_) => Ok(PyBoundMethod::new_ref(cls, zelf.callable.lock().clone(), &vm.ctx).into()), | ||
| Ok(_descr_get) => vm.invoke(&_descr_get, (cls.clone(), cls)), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_descr_get is unnecessarily _ prefixed
vm/src/builtins/classmethod.rs
Outdated
| let doc = vm.unwrap_pyresult(doc); | ||
| let obj = vm.unwrap_pyresult(result.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a correct error handling.
Both of them can be Err and they will panic.
vm/src/builtins/classmethod.rs
Outdated
| fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult { | ||
| PyClassMethod { | ||
| callable: PyMutex::new(callable), | ||
| let result: PyResult<PyObjectRef> = PyClassMethod { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because PyResult = PyResult<PyObjectRef>, this is redundant.
vm/src/builtins/classmethod.rs
Outdated
| PyClassMethod { | ||
| callable: PyMutex::new(callable), | ||
| let result: PyResult<PyObjectRef> = PyClassMethod { | ||
| callable: PyMutex::new(callable.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to get __doc__ before making PyClassMethod to avoid clone.
vm/src/builtins/classmethod.rs
Outdated
| let result: PyResult<PyObjectRef> = PyClassMethod { | ||
| callable: PyMutex::new(callable.clone()), | ||
| } | ||
| .into_ref_with_type(vm, cls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd like to propagate error here before later handling
| .into_ref_with_type(vm, cls) | |
| .into_ref_with_type(vm, cls)? |
|
dependency of #3862 |
vm/src/builtins/classmethod.rs
Outdated
| match doc { | ||
| Err(_) => None, | ||
| Ok(doc) => Some(obj.set_attr("__doc__", doc, vm)), | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| match doc { | |
| Err(_) => None, | |
| Ok(doc) => Some(obj.set_attr("__doc__", doc, vm)), | |
| }; | |
| if let Ok(doc) = doc { | |
| obj.set_attr("__doc__", doc, vm)?; | |
| } |
set_attr result need to be checked with ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points!
Check 'Named Expressions Need Not Be Parenthesized' Section
youknowone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thank you for contributing!
|
|
Except test_expressions in test_decorators.py file.
Now it is working with full test_decorators.py test file.