On Fri, 8 Apr 2022, 09:30 Malthe, <mbo...@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.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/IS7WHO3ZL33D4PSHWFSLU4D4WQ5736MY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to