-
Notifications
You must be signed in to change notification settings - Fork 371
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
rename defclass to class #899
Comments
On the other hand, we have |
I think maintaining the analogy to
We do that, but you know, I don't think we need to do that. By bypassing Python's parser and constructing
A simple experiment suggests we'd likely be able to do the same for
|
FWIW, I removed the python builtin check, and the following worked just fine: (def class 1)
(defclass Foo [] (defn zing [self] (print "zing!")))
(def f (Foo))
(.zing f)
(print class) Perhaps we should allow Python keywords to be used in Hy? Or at least, some of them. |
By that logic we should have
...
You know, maybe we should. This would let us get rid of I was under the impression that this would break Hy<->Python interop, but maybe it doesn't have to if we provide workarounds? For example, we allow Unicode symbols because Hy treats the equivalent Punycode as the same symbol, and this alias also works in Python. Python actually does allow reserved words as attributes, so that's not a problem either. >>> class namespace:
pass
>>> namespace.foo = 2
>>> namespace.foo
2
>>> namespace.class = 42
SyntaxError: invalid syntax
>>> setattr(namespace,'class',42)
>>> namespace.class
SyntaxError: invalid syntax
>>> getattr(namespace,'class')
42 You don't get the sugar, but it does work. I think # from class import class as Class
from importlib import import_module
Class = getattr(import_module('class'), 'class') I would want this tested though. The reverse is also a concern, e.g. can Hy import a Python module named Are there other cases interop would break that I'm not thinking of? Are there workarounds? |
Well, I think if one uses reserved python keywords in Hy code, that's not something we should care about. If one intentionally makes it hard to interoperate with their code from Python (or Hy), that's not something we should be responsible for. One can already make interop a pain, this wouldn't be any different. In short, I'd 👍 a PR that removes the python keyword checking lines, and as such 👎 on |
Same here, 👍 for removing the keyword checking, 👎 for renaming |
Looks like this is staying as |
class
is a reserved word in Python, and so is already reserved in Hy,but doesn't do anything useful.
And
class
is shorter to type.The text was updated successfully, but these errors were encountered: