python-trio / flake8-async

Highly opinionated linter for Trio code
https://flake8-async.readthedocs.io
MIT License
17 stars 2 forks source link

code cleanup after 91x PR #145

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

Fix comments from #143 and general minor code cleanup

jakkdl commented 1 year ago

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.

jakkdl commented 1 year ago

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 :smiley:

    # length > sys.maxsize
    for i in range(27670116110564327421):
        await foo()
    yield
Zac-HD commented 1 year ago

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 commented 1 year ago

ooh, nice!