this post was submitted on 04 Jul 2023
17 points (87.0% liked)

Python

6288 readers
3 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] o11c 3 points 1 year ago (1 children)

The with approach would work if you use the debugger to change the current line I think.

I don't understand why this stop using ASTs in favor of buggy regexes - you're allowed to do whatever you want during the codec ...

Don't forget to handle increment before continue.

The main time I miss C-style for loops is dealing with linked lists and when manipulating the current iteration.

The former should be easy enough - make the advancement provide __getattr__ expressions.

The latter already works since it is in fact being transformed into a while. It's impossible if you try to use for though.

[โ€“] qwop 2 points 1 year ago

If it's valid syntax you can technically do pretty much whatever you want at runtime with enough hacks. I know pytest does some pretty crazy stuff to get nicer error messages from asserts (e.g. so it can display the value of a and b for assert a == b)

As soon as it's invalid syntax it becomes harder. You can't parse it into an ast, which I assume is why they used regex.