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

code cleanup after 91x PR #145

Merged
merged 1 commit into from
Mar 6, 2023
Merged

code cleanup after 91x PR #145

merged 1 commit into from
Mar 6, 2023

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Feb 28, 2023

Fix comments from #143 and general minor code cleanup

@jakkdl
Copy link
Member Author

jakkdl commented Feb 28, 2023

Actually, since I landed on ast.literal_eval being pretty much the same as matching against an integer + handling unary operation, I rewrote iter_guaranteed_once_cst not to need cst_literal_eval. It probably wouldn't be very hard at all to evaluate unary/binary ops either, and range(10*23) isn't that uncommon. Can open an issue for it

And with the only remaining user of it being visit_While_test ... and I don't think we care about handling while [1, 2]: ... (and can get it for free if libcst implements evaluated_value for containers), I rewrote that one as well .. and completely removed cst_literal_eval.

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Minor nitpicks but great overall, go ahead and merge once you've addressed to your satisfaction 😁

@@ -28,7 +28,7 @@

T = TypeVar("T", bound=Flake8TrioVisitor)
T_CST = TypeVar("T_CST", bound=Flake8TrioVisitor_cst)
T_EITHER = TypeVar("T_EITHER", Flake8TrioVisitor, Flake8TrioVisitor_cst)
T_EITHER = TypeVar("T_EITHER", bound=Flake8TrioVisitor | Flake8TrioVisitor_cst)
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 this | syntax requires Python 3.10?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine due to from __future__ import annotations?
But regardless, tests run with <3.10, and I don't think we care about whether pyright running on 3.9 passes.

Copy link
Member

Choose a reason for hiding this comment

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

🤦 it's fine at runtime because we're in an if TYPE_CHECKING: block and so it never actually runs, nevermind.

Copy link
Member Author

Choose a reason for hiding this comment

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

haha I didn't realize that either, https://github.com/snok/flake8-type-checking doing it's job!

Comment on lines +177 to +178
if isinstance(arg.operator, cst.Minus):
value = -value
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Although I suspect it's quite rare to invert bits in range loops 😅

Copy link
Member

Choose a reason for hiding this comment

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

I certainly hope so! At large enough scale though, someone is bound to...

Copy link
Member Author

Choose a reason for hiding this comment

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

And of course this checker is gonna reach that scale 😁

flake8_trio/visitors/helpers.py Outdated Show resolved Hide resolved
flake8_trio/visitors/visitor91x.py Outdated Show resolved Hide resolved
tests/eval_files/trio910.py Outdated Show resolved Hide resolved
@jakkdl
Copy link
Member Author

jakkdl commented Mar 6, 2023

Reading through https://docs.python.org/3/library/stdtypes.html#range it mentioned len not working with sys.maxsize - so code now handles very long loops now as well 😃

    # length > sys.maxsize
    for i in range(27670116110564327421):
        await foo()
    yield

@jakkdl jakkdl merged commit c319cc4 into python-trio:main Mar 6, 2023
@jakkdl jakkdl deleted the libcst_91x branch March 6, 2023 13:13
@Zac-HD
Copy link
Member

Zac-HD commented Mar 6, 2023

Reading through https://docs.python.org/3/library/stdtypes.html#range it mentioned len not working with sys.maxsize

Heh, that note is my fault 😂 (Hypothesis is a great way to find edge cases...)

@jakkdl
Copy link
Member Author

jakkdl commented Mar 7, 2023

ooh, nice!

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