Added self and self_class to PySuper#3683
Conversation
|
@youknowone any tips on this? :) |
youknowone
left a comment
There was a problem hiding this comment.
Please add tests to extra_tests/snippets/builtin_super.py to ensure they are working same in CPython and RustPython.
Otherwise, you can find related tests from Lib/test/test_super.py and remove skip/unexpectedFailure decorator there. But I don't think these features tests are in the current version of test file.
|
|
||
| #[pyproperty(magic)] | ||
| fn thisclass(&self) -> PyTypeRef { | ||
| fn __thisclass__(&self) -> PyTypeRef { |
There was a problem hiding this comment.
(magic) means it will automatically add __s to its name.
There was a problem hiding this comment.
But the problem that I was having was that I can't have one of the functions named self, that's why I changed the names.
There was a problem hiding this comment.
Thank you for sharing your motivation. Now I understand what's going on.
But still, if you had problem with __self__, why did you change this function?
Use magic as much as possible. But do not use magic if it doesn't fit. Search for fn __set__ and fn __name__ to check other similar cases as examples.
There was a problem hiding this comment.
Thank you for your feedback, will keep working on this :)
|
@djrmarques did you set your git config user.email correctly? |
| } | ||
|
|
||
| #[pyproperty(magic)] | ||
| fn __self_class__(&self) -> Option<PyTypeRef> { |
There was a problem hiding this comment.
As youknowone said, magic in #[pyproperty] attach two underscores at the left-right sides automatically. This code leads to the below result.
>>>>> super(list).__self_class__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'super' object has no attribute '__self_class__'. Did you mean: '____self_class____'?You can use #[pyproperty(name = "__self__")] instead of magic.
The reserved keyword self could be replaced with zelf.
| match &self.obj { | ||
| Some((_, obj_type)) => Some(obj_type.clone()), | ||
| _ => None, | ||
| } |
There was a problem hiding this comment.
This code is also considerable.
self.obj.as_ref().map(|(_, obj_type)| obj_type.clone())Same code can be used for __self__
There was a problem hiding this comment.
I prefer this form:
| match &self.obj { | |
| Some((_, obj_type)) => Some(obj_type.clone()), | |
| _ => None, | |
| } | |
| Some(self.obj.as_ref()?.1.clone()) |
There was a problem hiding this comment.
The lint failure doesn't look related to this PR. (#3690)
|
Like most of upstreams, we only merge from upstream, so expecting every PR doesn't include any merge commit inside. Check this document if you are interested in: https://docs.gitlab.com/ee/topics/git/git_rebase.html |
youknowone
left a comment
There was a problem hiding this comment.
Looks good now.
Please change the status 'Ready for review` once you feel it's done
|
Thanks for the support on this. Probably going to just add some tests and possibly also figure out the rebase thing and then change it to ready |
|
Will make another PR for the same issue, this time without any merge commits and with relevant tests added. I am not even sure why this got closed, possibly because I did a force push on my fork branch? |
|
it seems you pushed the same commit of upstream/master to your patch branch. In that case, github automatically closes the PR. (I don't like the behavior) |
Hello.
Submitting this PR as a draft because I would like to get some feedback about #3610.
Do I have the right idea here or is this completely wrong?
Thank you!