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

Skip to content

Conversation

MementoRC
Copy link
Contributor

Proposing to add the possibility to insert statement before a node. This was found useful when combining 2 methods and needing to conserve the order of execution

Copy link
Owner

@isidentical isidentical left a comment

Choose a reason for hiding this comment

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

Can we also have some tests where we insert something at the top of the module, just before the last statement, between two statements using InsertBefore, and doing some mixed stuff with yields (composite actions) where we insert something before and then after and then before in the same match. Probably these should live in the test_actions.py. But overall, amazing PR! Love it.

Comment on lines 235 to 238
def _stack_effect(self) -> tuple[ast.AST, int]:
# Adding a statement right after the node will need to be reflected
# in the block.
return (self.node, 1)
Copy link
Owner

Choose a reason for hiding this comment

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

Since we are adding a statement right before a new node, this needs to be -1 right?

Suggested change
def _stack_effect(self) -> tuple[ast.AST, int]:
# Adding a statement right after the node will need to be reflected
# in the block.
return (self.node, 1)
def _stack_effect(self) -> tuple[ast.AST, int]:
# Adding a statement right before the node will need to be reflected
# in the block.
return (self.node, -1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is not going to work with _apply_multiple as it seems that the top of the stack is referenced to the input node, setting -1 does not seem to be a meaningful stack effect.
Maybe a Replace+InsertAfter is how to handle the InsertBefore with _apply_multiple?

Adding consideration for negative offset in graph_access.py
@isidentical
Copy link
Owner

Looks amazing, all of the tests are super clear and the code is very clean and slick. Thank you so much for working on this ❤️ 💯

@isidentical isidentical merged commit 609a5b2 into isidentical:main Jan 1, 2023
@MementoRC
Copy link
Contributor Author

Thank you, that means a lot! Happy New Year!

@MementoRC
Copy link
Contributor Author

My mistake, but there is a bug in this commit. The decorators are not pulled-in with the definition:

    INPUT_SOURCE = """
        @decorate
        def test():
            test_this()"""

    EXPECTED_SOURCE = """
        await async_test()
        @decorate
        def test():
            test_this()"""

   ACTUAL_SOURCE = """
        @decorate
        await async_test()
        def test():
            test_this()"""

I added the test and figuring out how to quickly resolve it

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.

2 participants