Skip to content
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

NameError for HyList, HyDict ... #1045

Closed
nalssee opened this issue Apr 14, 2016 · 7 comments · Fixed by #1979
Closed

NameError for HyList, HyDict ... #1045

nalssee opened this issue Apr 14, 2016 · 7 comments · Fixed by #1979

Comments

@nalssee
Copy link

nalssee commented Apr 14, 2016

Evaluating HyDict raises a NameError but once I evaluate '{}, it is defined in the env.

So I had to write like (instance? (type '{}) expr) instead of (instance? HyDict expr).

All the other HyObjects are the same.

I'm not sure if it is an intended behaviour or a bug.

@refi64
Copy link
Contributor

refi64 commented Apr 14, 2016

Each of the classes in within a module in hy.models:

  • HyDict is in hy.models.dict.
  • HyList is in hy.models.list.
  • etc.

@gilch
Copy link
Member

gilch commented Apr 14, 2016

Hy doesn't always import things until it needs them. You can use hy --spy to see what's going on. (--spy attempts to show you the Python code that would generate the same AST Hy has generated.)

=> HyDict
HyDict
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'HyDict' is not defined
=> '{}
from hy import HyDict
HyDict([])
{}
=> HyDict
HyDict
<class 'hy.models.dict.HyDict'>

The key line is from hy import HyDict. You can do this yourself if you prefer.

@refi64
Copy link
Contributor

refi64 commented Mar 23, 2017

Odd behavior, but intentional. I'll just close this for now.

@Kodiologist
Copy link
Member

Actually, I'm inclined to think this a bug; if we need to import a name that isn't a Hy builtin, it should be imported with a gensym. But it would make sense to make HyList etc. builtins.

@tuturto
Copy link
Contributor

tuturto commented Mar 24, 2017

Indeed, would make sense to have HyDict and friends available without explicitly importing them.

@Kodiologist Kodiologist added the bug label Apr 2, 2017
@gilch
Copy link
Member

gilch commented Jul 25, 2017

Let's add the Hy models to core then.

@Kodiologist
Copy link
Member

Gilch (#1360 (comment)) mentioned that HyCons isn't auto-imported in the way that the other Hy model types currently are. I'm guessing that's just an oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

5 participants