-
-
Notifications
You must be signed in to change notification settings - Fork 2
reimplement trio100 & trio101 with libcst #142
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
Conversation
Ah, looks like the CI failure is due to shed not fixing everything in one go. I've noticed that happening frequently which is somewhat annoying, will track down the cause and open an issue in shed. |
c77b2a8
to
3c85498
Compare
Fixed the CI, and cribbed your try/finally solution for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking nice! I think I was anticipating a considerably gnarlier migration...
I'd appreciate a response to super().__init__()
and the WithItem
thing; other comments don't need to be addressed before merging or perhaps at all.
flake8_trio/visitors/helpers.py
Outdated
|
||
return m.matches( | ||
func, | ||
m.FunctionDef( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally a little wary about such deeply-indented nested calls; maybe the m.Decorator(...)
could be pulled out as a named variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pulled out a list_contains
- it's close to being usable in with_has_item
as well, will likely iterate on these as I use them in more rewritten visitors/transformers.
return updated_node | ||
|
||
@m.visit(m.Await() | m.For(asynchronous=m.Asynchronous())) | ||
# can't use m.call_if_inside(m.With), since it matches parents *or* the node itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to write a helper function for this at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, I hadn't even considered writing my own decorators. Hell yes I want this, would be very useful in shed as well - I'm pretty sure there's at least one bad matcher due to this. But yeah, for another PR.
3c85498
to
cf468bf
Compare
you keep underestimating how good the [infra]structure/patterns I've built up are 😁 Though I did spend a lot of time on polishing this, and there's quite a bit of potential future gnarl left. |
Hofstadter's law has earned my respect, but you're right - kudos! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny tweak below, but this looks good to me. I'm inclined to merge (with or without tweak) in the morning and release a new version, what do you reckon?
cf468bf
to
3feea1a
Compare
Tweaked and ready to be shipped! And good call, this is nicer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
# need to use Union due to https://github.com/Instagram/LibCST/issues/870 | ||
def checkpoint_node(self, node: Union[cst.Await, cst.For, cst.With]): | ||
if self.has_checkpoint_stack: | ||
self.has_checkpoint_stack[-1] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out getting future annotations with get_type_hints
is not possible, though I think an alternative to using Union is stringifying the annotation.
https://stackoverflow.com/questions/66006087/how-to-use-typing-get-type-hints-with-pep585-in-python3-8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://discuss.python.org/t/pep-649-deferred-evaluation-of-annotations-tentatively-accepted/21331 for background, this is a long-running problem which should at least get better from 3.12 😌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time to re-read that PEP again :D
Oh and this will solve @dataclass
annotation troubles as well!
Also changed how trio100 works to avoid missed cases where a function is defined inside the with statement.
100 & 101 moved into their own files.
I spent some time trying to get batching to work,
BatchedVisitor
is not compatible withMatcherDecoratableVisitor
- and especially not with transformers. Tried dynamically creating a class that inherited from all enabled visitors, but ran into so many minor headaches with that approach I abandoned it. Might revisit once all visitors are changed to cst, but for now it's certainly not worth the effort for the sake of speeding it up. There might be a case of wanting to do the transforms simultaneously in case one transform unlocks another, and stuff like that.I thought batching would be required, since the utility visitors are separate classes, but I think that can be made to work by having error classes that require the functionality of a utility visitor to inherit from it. But neither 100 nor 101 require any of the utility ones so didn't bother with it too much.
I'm waiting with enabling transforming for trio100 for a later PR, since that will require a bunch of UI changes / flags / etc.
Ended up opening a bunch of issues in pyright/libcst/mypy during the process, Instagram/LibCST#870 is probably the most relevant one - which is probably gonna be somewhat of a pain going forward if not fixed. (I didn't bother trying to stop shed from removing
Union
, but if possible that'd make it less painful.)