Skip to content

Added self and self_class to PySuper#3683

Closed
djrmarques wants to merge 0 commit into
RustPython:mainfrom
djrmarques:main
Closed

Added self and self_class to PySuper#3683
djrmarques wants to merge 0 commit into
RustPython:mainfrom
djrmarques:main

Conversation

@djrmarques
Copy link
Copy Markdown
Contributor

@djrmarques djrmarques commented May 3, 2022

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!

@djrmarques
Copy link
Copy Markdown
Contributor Author

@youknowone any tips on this? :)

Copy link
Copy Markdown
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.

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.

Comment thread vm/src/builtins/super.rs Outdated

#[pyproperty(magic)]
fn thisclass(&self) -> PyTypeRef {
fn __thisclass__(&self) -> PyTypeRef {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(magic) means it will automatically add __s to its name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback, will keep working on this :)

@youknowone
Copy link
Copy Markdown
Member

@djrmarques did you set your git config user.email correctly?
@Snowapril could you review this patch?

Comment thread vm/src/builtins/super.rs Outdated
}

#[pyproperty(magic)]
fn __self_class__(&self) -> Option<PyTypeRef> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread vm/src/builtins/super.rs Outdated
Comment on lines +119 to +122
match &self.obj {
Some((_, obj_type)) => Some(obj_type.clone()),
_ => None,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code is also considerable.

self.obj.as_ref().map(|(_, obj_type)| obj_type.clone())

Same code can be used for __self__

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer this form:

Suggested change
match &self.obj {
Some((_, obj_type)) => Some(obj_type.clone()),
_ => None,
}
Some(self.obj.as_ref()?.1.clone())

Copy link
Copy Markdown
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.

The lint failure doesn't look related to this PR. (#3690)

Comment thread vm/src/builtins/super.rs Outdated
@youknowone
Copy link
Copy Markdown
Member

Like most of upstreams, we only merge from upstream, so expecting every PR doesn't include any merge commit inside.
This is a simple PR, so we can squash it for this one. But learning rebase will be helpful if you want to make more PRs to RustPython or any other projects

Check this document if you are interested in: https://docs.gitlab.com/ee/topics/git/git_rebase.html

@youknowone youknowone self-requested a review May 7, 2022 11:02
Copy link
Copy Markdown
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 now.
Please change the status 'Ready for review` once you feel it's done

@djrmarques
Copy link
Copy Markdown
Contributor Author

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

@djrmarques
Copy link
Copy Markdown
Contributor Author

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?

@youknowone
Copy link
Copy Markdown
Member

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)

@djrmarques djrmarques mentioned this pull request May 7, 2022
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