Skip to content

Python: add test for Argument[0, self, self:] for instance methods #16155

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 3 commits into from
Apr 29, 2024

Conversation

yoff
Copy link
Contributor

@yoff yoff commented Apr 9, 2024

No description provided.

@yoff yoff added the no-change-note-required This PR does not need a change note label Apr 9, 2024
@github-actions github-actions bot added Python and removed no-change-note-required This PR does not need a change note labels Apr 9, 2024
SINK_F(y)

ms = c.explicit_self
SINK(ms(SOURCE)) # $ MISSING: flow="SOURCE, l:0 -> ms(SOURCE)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be marked as MISSING or as a SINK_F? I.e. do we want/expect Argument[self:] to work here? (Or anywhere..)

@yoff yoff marked this pull request as ready for review April 9, 2024 11:05
@yoff yoff requested a review from a team as a code owner April 9, 2024 11:05
Copy link
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

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

two things I don't quite understand

Comment on lines 132 to 135
m = c.instance_method
x, y = (SOURCE, NONSOURCE)
SINK(x) # $ flow="SOURCE, l:-1 -> x"
SINK_F(y)
Copy link
Member

Choose a reason for hiding this comment

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

you didn't use m here, which seems odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, indeed..

Comment on lines 137 to 138
ms = c.explicit_self
SINK(ms(SOURCE)) # $ MISSING: flow="SOURCE, l:0 -> ms(SOURCE)"
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 understand this test. You've added a flow summary for using keyword argument named self, but are passing in a positional argument...

That is, it's totally legal to do this:

class Foo:
    def method(s, *, self):
        # a method where you MUST pass in keyword argument `self`
        ....

I also don't quite understand why you've made a use of a bound-method, instead of just calling the method on the same line? that is, why not just rewrite the test to this?

Suggested change
ms = c.explicit_self
SINK(ms(SOURCE)) # $ MISSING: flow="SOURCE, l:0 -> ms(SOURCE)"
SINK(c.explicit_self(SOURCE)) # $ MISSING: flow="SOURCE, l:0 -> ms(SOURCE)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was to expose the self argument. The test is testing whether Argument[self:] resolves to that (and the test above does the same for Argument[self]).

But I did not manage to trigger that calling convention; I fixed that now..

Copy link
Member

Choose a reason for hiding this comment

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

I think you need to use c.explicit_self(self=SOURCE)... and then it's a test that even on an instance method you can use keyword arguments called self.

I don't think ☝️ is what you intended, but I think what I'm outlining above is the correct behavior MaD should exhibit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. And the tests agree too. I have added some comments to explain what is going on.

@yoff yoff requested a review from RasmusWL April 23, 2024 09:15
RasmusWL
RasmusWL previously approved these changes Apr 26, 2024
Copy link
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

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

Thanks for the updates 👍

yoff added 3 commits April 26, 2024 14:21
The way to expose the `self` arguemnt
is to call an instance method on the class,
not on the instance...
@yoff yoff force-pushed the python/MaD-method-arg-tests branch from 029804c to 3716b8c Compare April 26, 2024 12:22
@yoff
Copy link
Contributor Author

yoff commented Apr 26, 2024

Force pushed since conflicts were resolved cleanly by pull --rebase.

@yoff yoff requested a review from RasmusWL April 26, 2024 12:23
@yoff yoff merged commit 1c611fe into github:main Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants