Version 3.4.0
3.4.0 (2 May 2021) - Quasiquotes ahoy edition:
New:
- The unparser now recognizes hygienic captures and destructures them in debug mode. This makes the result much more readable when you unparse an AST that uses a lot of hygienic unquotes.
-
To see it in action, use
mcpyrate.debug.step_expansion
macro onunpythonic.syntax.tests.test_lazify
. See particularly the HasThon test; both the autocurry and the lazifier produce many hygienic captures.Without this helpful destructuring, the macro-expanded code is completely unreadable, but with this, it only exhibits mild symptoms of parenthesitis. For example, this snippet:
filename=callsite_filename()
becomes, after autocurry and lazification,
filename=$h[Lazy]((lambda: $h[maybe_force_args]($h[force]($h[currycall]), $h[Lazy]((lambda: $h[force]($h[callsite_filename]))))))
Here each
$h[...]
is a hygienic capture. That's seven captures for this very simple input! Compare this notation to the actual AST representation of, e.g.,$h[Lazy]
:__import__('mcpyrate.quotes', globals(), None, (), 0).quotes.lookup_value(('Lazy', b'\x80\x04\x95 \x00\x00\x00\x00\x00\x00\x00\x8c\x13unpythonic.lazyutil\x94\x8c\x04Lazy\x94\x93\x94.'))
-
Fixed:
-
The importer now reports the source location if destructuring a macro invocation candidate fails.
- Some internal functions, including
mcpyrate.expander.destructure_candidate
, now take a mandatoryfilename
kwarg for this purpose.
- Some internal functions, including
-
Fix detection of globally bound macro invocations (hygienic macro captures) in the helper method
mcpyrate.expander.ismacrocall
. -
Fix syntax analysis for detecting
expr
macro invocations inmcpyrate.expander.destructure_candidate
. Version 3.3.0 (and only that version) errored out on the AST forf()[...]
even iff
was not bound as a macro.