Skip to content
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

Architecture: Figure out how to get context #21

Closed
MartinThoma opened this issue Nov 7, 2020 · 9 comments
Closed

Architecture: Figure out how to get context #21

MartinThoma opened this issue Nov 7, 2020 · 9 comments

Comments

@MartinThoma
Copy link
Owner

Several issues are blocked, because I don't know yet how to get context.

For example, SIM 201 prevents not a==b and suggests a != b. In general, this seems to be a good rule.

As an exception, I want to leave it like this when it's in the context of throwing exceptions:

if not (a == b):
    return ValueError("Expected a==b")

But for this I need to know that the boolean operation not (a ==b) is in the context of an if-statement.

@Skylion007
Copy link
Contributor

@Skylion007
Copy link
Contributor

@MartinThoma Or better yet transformers.ParentChildNodeTransformer in astmonkey should work well. One of the AST libraries in the list should prove helpful: https://github.com/gyermolenko/awesome-python-ast

@Skylion007
Copy link
Contributor

After looking around, I really think astpath should be able to do queries with all the context you realistically need: (check the ReadMe: https://github.com/hchasestevens/astpath)

@MartinThoma
Copy link
Owner Author

Thank you!

This week (and probably all the time until Christmas) is super busy for me. I don't think I will have the time to look into it. But feel free to create a PR :-)

@MartinThoma
Copy link
Owner Author

https://stackoverflow.com/a/43311383/562769 might be it

@MartinThoma
Copy link
Owner Author

It's fixed: e301b8f - now every node has a parent attribute. It's a bit of a mess to fix the type annotations, but besides that it's fine.

@Skylion007
Copy link
Contributor

@MartinThoma Could have also just used typing .cast

@MartinThoma
Copy link
Owner Author

@Skylion007 Where? And cast to what? Feel free to make a PR if you see a simpler solution :-)

@Skylion007
Copy link
Contributor

Ah, nvm you are using dynamic attrs. Yeah, that will only work if you mark parent as an optional value and subclass them all. :/

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

No branches or pull requests

2 participants