Import expressions

Sorry, that’s not solving the same problem. That’s my fault; I didn’t articulate what I like about the capability in Rust, I just cited it as nice.

The thing I like is that when I’m deep in an algorithm:

while ready:
    head = heapq.heappop(ready)
    yield head
    for d in |

(| indicates my cursor)

Then I just want to write something valid without breaking my flow. Whether I refactor the import to the top of the file later, or not, or it drops out, is something I don’t have to worry about.

Particularly for something like itertools.chain(), I might only use it once in the whole module. If Python had an import expression I might never bother to change it.

I understand there’s a difference in semantics (laziness) in Python that isn’t in Rust, but the coding experience is nice and could work in Python.

1 Like