Add support for the Python 3.15+ lazy keyword#2292
Conversation
New in Python 3.15, there is a `lazy` keyword which allows for deferred imports. Also update the demo to make use of `lazy`, type annotations, and `None`, all of which make the demo a bit more complete.
|
Hi, thanks for this contribution! I think a thing that complicates this implementation is that Ref: https://peps.python.org/pep-0810/#grammar This may require some special handling similar to |
|
Ah! Sorry, I clearly under-thought this a little. (I got excited when it looks "so easy" 😉 ) I'm pretty out of practice in Ruby, but let me see if I can make the requisite changes to support this as a soft keyword. |
|
No worries at all, that's how it is :]. I think something like a lookahead with |
Account for the fact that `lazy` is also a valid identifier. Capture that you know it's a keyword *iff* the next token is `from` or `import`. Since there's no valid context in Python for putting two identifiers adjacent without an operator, we don't need to worry about what comes after `from` or `import`.
|
Of course, the moment I share that, I stare at it and don't... love it. I'd like to make |
The `from_import` state lexing now accounts for `lazy import` being the next tokens.
67a0d35 to
05f0e86
Compare
| # handle `lazy import` soft keyword usage | ||
| # since `import` is a hard keyword, we know that this usage has to be | ||
| # the soft-keyword case | ||
| rule %r/lazy(?=#{inline_ws}import)/, Keyword |
There was a problem hiding this comment.
A small nit, but import should probably have a \b at the end so it doesn't match things like important.
There was a problem hiding this comment.
Also I believe this will match lazyimport with no space, which should be an identifier. Probably the easiest to do is %r/lazy\b(?=#{inline_ws}import\b)/.
There was a problem hiding this comment.
👍 Yep, good catch! I didn't realize that inline_ws matches on "".
I've applied (co-authored commit! 😁 ).
Co-authored-by: Jeanine Adkisson <225017+jneen@users.noreply.github.com>


New in Python 3.15, there is a
lazykeyword which allows for deferredimports.
Also update the demo to make use of
lazy, type annotations, andNone,all of which make the demo a bit more complete.