-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior or #docs
/ __macros__
and __tags__
#1970
Comments
I've had tests fail intermittently with |
With the tag macro simplification, running (doc "#@")
(setv [out err] (.readouterr capsys))
> (assert (in "with-decorator tag macro" out))
E AssertionError in |
Yeah the problem is the disconnect between macros getting patched in at compile time vs macros that get compiled into the module's .pyc file. A related issue that illustrates this: ;; module_trap.hy
(defn toot_fn [s] (+ "fn TOOT " s))
(defmacro toot_mac [s] `(+ "mac TOOT " ~s))
(print (toot_fn "self"))
(print (toot_mac "self"))
;; confused.hy
(require module-trap)
(import module-trap)
(print (module-trap.toot_fn "imported"))
(print (module-trap.toot_mac "imported")) $ hy confused.hy
fn TOOT self
mac TOOT self
fn TOOT imported
mac TOOT imported
$ sed -i 's/TOOT/bloot/' module_trap.hy
$ hy confused.hy
fn bloot self
mac bloot self
fn bloot imported
mac TOOT imported # <-- !!
$ touch confused.hy
$ hy confused.hy
fn bloot self
mac bloot self
fn bloot imported
mac bloot imported Updating the module doesn't affect macros in |
Closed with #1971. |
There is no longer a test for hylang#1970, but this bug should no longer be applicable.
There is no longer a test for hylang#1970, but this bug should no longer be applicable.
A test of hylang#1946 remains in `tests/native_tests/macros_first_class.hy`, added by 9998e51. There is no longer a test for hylang#1970, but this bug should no longer be applicable.
A test of hylang#1946 remains in `tests/native_tests/macros_first_class.hy`, added by 9998e51. There is no longer a test for hylang#1970, but this bug should no longer be applicable.
A test of hylang#1946 remains in `tests/native_tests/macros_first_class.hy`, added by 9998e51. There is no longer a test for hylang#1970, but this bug should no longer be applicable.
Minimum viable test case, must be run from its own file (not from the REPL):
Ok so this one is a little weird but I think I know why it's happening.
TL;DR Hy patches in
__macros__
and__tags__
to a module only on an as-needed basis and only during compilation. As a result, you can end up with Hy modules that don't have these defined.Observed symptoms:
#doc @
fails with'__tags__' is not defined
.(deftag)
, the module now defines a__tags__
, but it's only populated with the tagbogus
— thus the#doc @
brings up the help page forNone
.(macroexpand)
, then Hy finally brings the@
tag macro into__tags__
, and you get the proper help page.Further weirdness!
Create two files like so:
When you run
runme.hy
, you get the help page forNone
.Without changing anything, run it again — now it fails with
'__tags__' is not defined
!On the first run the compiler patches in
__tags__
and__macros__
for the compilation process, but every subsequent run skips compilation and loads the pyc files from the pycache — and no code was ever produced to actually create a__tags__
inrunme.hy
.So far I only foresee this as a weird edge case of
#doc
and don't expect this leading to any real bugs, but it does produce confusing behavior for anyone doing introspection on Hy modules.Possible solutions:
__macros__
and__tags__
to every Hy module at runtime, possibly via theimport hy
statement, and pre-populate with the core macros/tags.#doc
has strange behavior if you use it outside the REPL (and also fix thetest-doc
test, that's how I stumbled across this).The text was updated successfully, but these errors were encountered: