On Fri, 8 Apr 2022, 09:30 Malthe, <mborch@gmail.com> wrote:
For example, `some_regex = @re.compile(...)`.

I like the idea of import expressions. I pitched it on Discourse recently: https://discuss.python.org/t/import-expressions/11582

However, I do not see hoisting as something that should be done by Python. In that thread it was suggested your IDE could do it, or maybe isort, which seems fine because it's at the programmer's discretion and ends up being explicit.

But, your proposed syntax is not usable because it is ambiguous. Exactly what you propose is already used for decorators in a way that the parser would not be able to distinguish a decorator from an import expression. Consider:

    @ham.spam()   # import expression or decorator?

     def eggs():
        ...

This currently parses as a decorator and for backwards compatibility that must not change, which means that import expressions would be usable in some contexts and not others purely based on what follows them.