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

Skip to content

Transform all async ast nodes into sync nodes#158

Merged
KevinHock merged 1 commit into
python-security:masterfrom
bcaller:await-transform
Jul 31, 2018
Merged

Transform all async ast nodes into sync nodes#158
KevinHock merged 1 commit into
python-security:masterfrom
bcaller:await-transform

Conversation

@bcaller
Copy link
Copy Markdown
Collaborator

@bcaller bcaller commented Jul 31, 2018

Transform all async ast nodes into sync nodes …
so that they can be handled identically. Sync and async nodes propagate
taint in exactly the same way.

Awaits are more or less removed:
return await x() is converted into return x().

Any AsyncFunctionDef is converted to a FunctionDef.

Same for AsyncFor and AsyncWith.

Using a transformer makes it easier to replace awaits everywhere (c.f. a different attempt at https://github.com/bcaller/pyt/commits/await ).
We have lots of places where we do isinstance(node, ast.Call) but for these we want it to function like isinstance(node, ast.Call) or (isinstance(node, ast.Await) and isinstance(node.value, ast.Call))

so that they can be handled identically. Sync and async nodes propagate
taint in exactly the same way.

Awaits are more or less removed:
`return await x()` is converted into `return x()`.

Any AsyncFunctionDef is converted to a FunctionDef.

Same for AsyncFor and AsyncWith.

Using a transformer makes it easier to replace awaits everywhere.
We have lots of places where we do `isinstance(node, ast.Call)` but for these we want it to function like `isinstance(node, ast.Call) or (isinstance(node, ast.Await) and isinstance(node.value, ast.Call))`
@KevinHock KevinHock self-requested a review July 31, 2018 17:48
@KevinHock
Copy link
Copy Markdown
Collaborator

This is genius! 😁 I'll review later today

Copy link
Copy Markdown
Collaborator

@KevinHock KevinHock left a comment

Choose a reason for hiding this comment

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

Looks great to me! 🚢

from pyt.core.transformer import AsyncTransformer


class TransformerTest(unittest.TestCase):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great tests :D

@KevinHock KevinHock merged commit 212e059 into python-security:master Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants