Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 13 commits into from
Jul 16, 2022
Merged

Fix decorators #3783

merged 13 commits into from
Jul 16, 2022

Conversation

ChJR
Copy link
Contributor

@ChJR ChJR commented Jun 12, 2022

Except test_expressions in test_decorators.py file.

Now it is working with full test_decorators.py test file.

@fanninpm
Copy link
Contributor

test_socket.py needs an update; I can tackle that later.

@youknowone
Copy link
Member

related to #3742

@ChJR ChJR force-pushed the feature/fix_decorators branch from a77ae32 to f2e62cf Compare June 21, 2022 14:37
}
}

impl Constructor for PyClassMethod {
type Args = PyObjectRef;

fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
PyClassMethod {
let _callable = callable.clone();
Copy link
Member

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.

Comment on lines 81 to 84
match obj.set_attr("__doc__", doc, vm) {
Err(e) => Err(e),
Ok(_) => result,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
match obj.set_attr("__doc__", doc, vm) {
Err(e) => Err(e),
Ok(_) => result,
}
obj.set_attr("__doc__", doc, vm)?;
result

@@ -41,9 +41,19 @@ impl Constructor for PyStaticMethod {
type Args = PyObjectRef;

fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
PyStaticMethod { callable }
let _callable = callable.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is another _callable

@ChJR
Copy link
Contributor Author

ChJR commented Jul 10, 2022

Good points. I will change the codes.

Comment on lines 58 to 62
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)),
}
Copy link
Member

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

Comment on lines 77 to 78
let doc = vm.unwrap_pyresult(doc);
let obj = vm.unwrap_pyresult(result.clone());
Copy link
Member

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.

}
}

impl Constructor for PyClassMethod {
type Args = PyObjectRef;

fn py_new(cls: PyTypeRef, callable: Self::Args, vm: &VirtualMachine) -> PyResult {
PyClassMethod {
callable: PyMutex::new(callable),
let result: PyResult<PyObjectRef> = PyClassMethod {
Copy link
Member

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.

PyClassMethod {
callable: PyMutex::new(callable),
let result: PyResult<PyObjectRef> = PyClassMethod {
callable: PyMutex::new(callable.clone()),
Copy link
Member

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.

PyClassMethod {
callable: PyMutex::new(callable),
let result: PyResult<PyObjectRef> = PyClassMethod {
callable: PyMutex::new(callable.clone()),
}
.into_ref_with_type(vm, cls)
Copy link
Member

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

Suggested change
.into_ref_with_type(vm, cls)
.into_ref_with_type(vm, cls)?

@youknowone
Copy link
Member

dependency of #3862

Comment on lines 78 to 81
match doc {
Err(_) => None,
Ok(doc) => Some(obj.set_attr("__doc__", doc, vm)),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points!

ChJR added 2 commits July 16, 2022 21:16
Check 'Named Expressions Need Not Be Parenthesized' Section
Copy link
Member

@youknowone youknowone left a 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!

@youknowone
Copy link
Member

youknowone commented Jul 16, 2022

oh, this is unexpected errors ok, that's solved by retry

@youknowone youknowone merged commit d9d4538 into RustPython:main Jul 16, 2022
@ChJR ChJR deleted the feature/fix_decorators branch July 17, 2022 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants