internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: hylang/hy

Issue:
odd little exprs sprinkled throughout code branches
as seen with hy2py / website when I can be bothered to update it (working on it now)



Discussion:
That's also annoying on the REPL, as those get printed if they are non-nil.

The issue is around 9d8accb. I'm thinking we should optimize `Name`s if they are tacked on statements, which would leave the `(try xxx (except [NameError] yyy))` testcase untouched.


Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -193,9 +193,13 @@ def expr_as_stmt(self):
         This is useful when we want to use the stored expression in a
         statement context (for instance in a code branch).
 
+        We drop ast.Names if they are appended to statements, as they
+        can't have any side effect. "Bare" names still get converted to
+        statements.
+
         If there is no expression context, return an empty result.
         """
-        if self.expr:
+        if self.expr and not (isinstance(self.expr, ast.Name) and self.stmts):
             return Result() + ast.Expr(lineno=self.expr.lineno,
                                        col_offset=self.expr.col_offset,
                                        value=self.expr)


Test patch:
diff --git a/tests/compilers/test_compiler.py b/tests/compilers/test_compiler.py
--- a/tests/compilers/test_compiler.py
+++ b/tests/compilers/test_compiler.py
@@ -1,4 +1,5 @@
 # Copyright (c) 2013 Julien Danjou <julien@danjou.info>
+# Copyright (c) 2013 Nicolas Dandrimont <nicolas.dandrimont@crans.org>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -29,6 +30,7 @@
 
 from hy.models.expression import HyExpression
 from hy.models.list import HyList
+from hy.models.symbol import HySymbol
 from hy.compiler import HyASTCompiler
 
 
@@ -63,3 +65,24 @@ def test_fn_compiler_empty_function(self):
         self.assertIsInstance(stmt.body[0], ast.Pass)
 
         self.assertIsInstance(ret.expr, ast.Name)
+
+    def test_compiler_bare_names(self):
+        """Check that the compiler doesn't drop bare names from code branches"""
+        ret = self.c.compile(self._make_expression(HySymbol("do"),
+                                                   HySymbol("a"),
+                                                   HySymbol("b"),
+                                                   HySymbol("c")))
+
+        # We expect two statements and a final expr.
+        self.assertEqual(len(ret.stmts), 2)
+        stmt = ret.stmts[0]
+        self.assertIsInstance(stmt, ast.Expr)
+        self.assertIsInstance(stmt.value, ast.Name)
+        self.assertEqual(stmt.value.id, "a")
+        stmt = ret.stmts[1]
+        self.assertIsInstance(stmt, ast.Expr)
+        self.assertIsInstance(stmt.value, ast.Name)
+        self.assertEqual(stmt.value.id, "b")
+        expr = ret.expr
+        self.assertIsInstance(expr, ast.Name)
+        self.assertEqual(expr.id, "c")
Repository: hylang/hy

Issue:
Add reader macros
so we can use `'(foo bar)` and `(foo bar ,baz)`.



Discussion:

Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -1096,24 +1096,14 @@ def compile_list_comprehension(self, expr):
     def compile_kwapply_expression(self, expr):
         expr.pop(0)  # kwapply
         call = self.compile(expr.pop(0))
-        kwargs = expr.pop(0)
+        kwargs = self.compile(expr.pop(0))
 
         if type(call.expr) != ast.Call:
             raise HyTypeError(expr, "kwapplying a non-call")
 
-        if type(kwargs) != HyDict:
-            raise TypeError("kwapplying with a non-dict")
+        call.expr.kwargs = kwargs.force_expr
 
-        keywords = []
-        ret = Result()
-        for x in kwargs:
-            ret += self.compile(kwargs[x])
-            keywords.append(ast.keyword(arg=ast_str(x),
-                                        value=ret.force_expr))
-
-        call.expr.keywords = keywords
-
-        return ret + call
+        return kwargs + call
 
     @builds("not")
     @builds("~")


Test patch:
diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy
--- a/tests/native_tests/language.hy
+++ b/tests/native_tests/language.hy
@@ -143,7 +143,10 @@
 
 (defn test-kwargs []
   "NATIVE: test kwargs things."
-  (assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"})))
+  (assert (= (kwapply (kwtest) {"one" "two"}) {"one" "two"}))
+  (setv mydict {"one" "three"})
+  (assert (= (kwapply (kwtest) mydict) mydict))
+  (assert (= (kwapply (kwtest) ((fn [] {"one" "two"}))) {"one" "two"})))
 
 
 (defn test-dotted []
Repository: hylang/hy

Issue:
hy raises ImportError out of the box
This is on Python 2.6.

May be related to #37

I think `hy` should probably install the `importlib` dependency at installation time, or the docs should state clearly that `importlib` needs to be installed ahead of time.  Or, (worst case) state that Python 2.6 is not supported.

```
(env)09:52:13 Python (master) >  hy
Traceback (most recent call last):
  File "/Users/jacobsen/env/bin/hy", line 9, in <module>
    load_entry_point('hy==0.9.10', 'console_scripts', 'hy')()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pkg_resources.py", line 343, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pkg_resources.py", line 2354, in load_entry_point
    return ep.load()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pkg_resources.py", line 2060, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/Users/jacobsen/Programming/Python/hy/hy/__init__.py", line 37, in <module>
    import hy.importer  # NOQA
  File "/Users/jacobsen/Programming/Python/hy/hy/importer.py", line 22, in <module>
    from hy.compiler import hy_compile
  File "/Users/jacobsen/Programming/Python/hy/hy/compiler.py", line 44, in <module>
    import importlib
ImportError: No module named importlib
(env)09:52:13 Python (master) >  pip install importlib
Downloading/unpacking importlib
  Downloading importlib-1.0.2.tar.bz2
  Running setup.py egg_info for package importlib
Installing collected packages: importlib
  Running setup.py install for importlib
Successfully installed importlib
Cleaning up...
(env)09:52:21 Python (master) >  hy
hy 0.9.10
=> 
```



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -48,6 +48,7 @@
 install_requires = ['rply>=0.6.2']
 if sys.version_info[:2] < (2, 7):
     install_requires.append('argparse>=1.2.1')
+    install_requires.append('importlib>=1.0.2')
 if os.name == 'nt':
     install_requires.append('pyreadline==2.0')
 


Test patch:
Repository: hylang/hy

Issue:
Translate foo? -> is_foo 
Andddd discuss 



Discussion:
:+1: until better proposal

the only other option I can think right now would be a more common-lisp approach of adding a "-p" suffix (from predicate) but I don't like that naming convention.

:+1:

Like @Willyfrog, I'd be happier with `is_foo` than with `foo-p` (I hate this in Emacs Lisp too).

:+1:  prefer this over the predicate form

:shipit:
:+1: 
I'm not sure if there is any better way of solving it. It's also cleaner then the -p as mentioned above.


Resolving patch:
diff --git a/hy/lex/parser.py b/hy/lex/parser.py
--- a/hy/lex/parser.py
+++ b/hy/lex/parser.py
@@ -238,6 +238,9 @@ def t_identifier(p):
     if "-" in obj and obj != "-":
         obj = obj.replace("-", "_")
 
+    if obj.endswith("?") and obj != "?":
+        obj = "is_%s" % (obj[:-1])
+
     return HySymbol(obj)
 
 


Test patch:
diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy
--- a/tests/native_tests/language.hy
+++ b/tests/native_tests/language.hy
@@ -551,6 +551,12 @@
     (assert (= -_- "what?"))))
 
 
+(defn test-symbol-question-mark []
+  "NATIVE: test foo? -> is_foo behavior"
+  (let [[foo? "nachos"]]
+    (assert (= is_foo "nachos"))))
+
+
 (defn test-and []
   "NATIVE: test the and function"
   (let [[and123 (and 1 2 3)]
Repository: hylang/hy

Issue:
Allow macros to return None
```
 (defmacro foo [])
 (foo) 
```

Will break as macros are not handling the NoneType yet



Discussion:

Resolving patch:
diff --git a/hy/macros.py b/hy/macros.py
--- a/hy/macros.py
+++ b/hy/macros.py
@@ -84,7 +84,8 @@ def require(source_module, target_module):
     complex: HyComplex,
     str_type: HyString,
     dict: lambda d: HyDict(_wrap_value(x) for x in sum(d.items(), ())),
-    list: lambda l: HyList(_wrap_value(x) for x in l)
+    list: lambda l: HyList(_wrap_value(x) for x in l),
+    type(None): lambda foo: HySymbol("None"),
 }
 
 


Test patch:
diff --git a/tests/native_tests/native_macros.hy b/tests/native_tests/native_macros.hy
--- a/tests/native_tests/native_macros.hy
+++ b/tests/native_tests/native_macros.hy
@@ -34,6 +34,9 @@
 (defmacro a-dict [] {1 2})
 (assert (= (a-dict) {1 2}))
 
+(defmacro a-none [])
+(assert (= (a-none) None))
+
 ; A macro calling a previously defined function
 (eval-when-compile
  (defn foo [x y]
Repository: hylang/hy

Issue:
Multi argument get
Ever wanted to use get with multiple arguments?

``` clojure
(get foo bar baz quux)
```

Equivalent to python's:

``` python
foo[bar][baz][quux]
```

Well, if this Feature Request masquerading as an Issue is accepted and implemented, then you can! Then you can get all the things.

Suggested by @olasd on IRC.



Discussion:

Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -1086,18 +1086,25 @@ def _compile_import(expr, module, names=None, importer=ast.Import):
         return rimports
 
     @builds("get")
-    @checkargs(2)
+    @checkargs(min=2)
     def compile_index_expression(self, expr):
         expr.pop(0)  # index
-        val = self.compile(expr.pop(0))  # target
-        sli = self.compile(expr.pop(0))  # slice
 
-        return val + sli + ast.Subscript(
-            lineno=expr.start_line,
-            col_offset=expr.start_column,
-            value=val.force_expr,
-            slice=ast.Index(value=sli.force_expr),
-            ctx=ast.Load())
+        val = self.compile(expr.pop(0))
+        slices, ret = self._compile_collect(expr)
+
+        if val.stmts:
+            ret += val
+
+        for sli in slices:
+            val = Result() + ast.Subscript(
+                lineno=expr.start_line,
+                col_offset=expr.start_column,
+                value=val.force_expr,
+                slice=ast.Index(value=sli),
+                ctx=ast.Load())
+
+        return ret + val
 
     @builds("del")
     @checkargs(min=1)


Test patch:
diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py
--- a/tests/compilers/test_ast.py
+++ b/tests/compilers/test_ast.py
@@ -253,7 +253,6 @@ def test_ast_bad_get():
     "Make sure AST can't compile invalid get"
     cant_compile("(get)")
     cant_compile("(get 1)")
-    cant_compile("(get 1 2 3)")
 
 
 def test_ast_good_slice():
diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy
--- a/tests/native_tests/language.hy
+++ b/tests/native_tests/language.hy
@@ -129,7 +129,16 @@
 (defn test-index []
   "NATIVE: Test that dict access works"
   (assert (= (get {"one" "two"} "one") "two"))
-  (assert (= (get [1 2 3 4 5] 1) 2)))
+  (assert (= (get [1 2 3 4 5] 1) 2))
+  (assert (= (get {"first" {"second" {"third" "level"}}}
+                  "first" "second" "third")
+             "level"))
+  (assert (= (get ((fn [] {"first" {"second" {"third" "level"}}}))
+                  "first" "second" "third")
+             "level"))
+  (assert (= (get {"first" {"second" {"third" "level"}}}
+                  ((fn [] "first")) "second" "third")
+             "level")))
 
 
 (defn test-lambda []
Repository: hylang/hy

Issue:
+ and * should be callable without arguments
I didn't find an issue open or closed regarding this so forgive me if this has been brought up before. Both `+` and `*` should return their identity values, `0` and `1` respectively, when called with no arguments. This is the typical behavior for these functions in lisps.



Discussion:
word. this should be an easyish fix


Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -1343,11 +1343,9 @@ def compile_compare_op_expression(self, expression):
                                  lineno=e.start_line,
                                  col_offset=e.start_column)
 
-    @builds("+")
     @builds("%")
     @builds("/")
     @builds("//")
-    @builds("*")
     @builds("**")
     @builds("<<")
     @builds(">>")
@@ -1384,6 +1382,23 @@ def compile_maths_expression(self, expression):
                              col_offset=child.start_column)
         return ret
 
+    @builds("+")
+    @builds("*")
+    def compile_maths_expression_mul(self, expression):
+        if len(expression) > 2:
+            return self.compile_maths_expression(expression)
+        else:
+            id_op = {"+": HyInteger(0), "*": HyInteger(1)}
+
+            op = expression.pop(0)
+            arg = expression.pop(0) if expression else id_op[op]
+            expr = HyExpression([
+                HySymbol(op),
+                id_op[op],
+                arg
+            ]).replace(expression)
+            return self.compile_maths_expression(expr)
+
     @builds("-")
     @checkargs(min=1)
     def compile_maths_expression_sub(self, expression):


Test patch:
diff --git a/tests/native_tests/math.hy b/tests/native_tests/math.hy
--- a/tests/native_tests/math.hy
+++ b/tests/native_tests/math.hy
@@ -8,7 +8,9 @@
 
 (setv test_mult (fn []
                   "NATIVE: Test multiplication."
-                  (assert (= 4 (square 2)))))
+                  (assert (= 4 (square 2)))
+                  (assert (= 8 (* 8)))
+                  (assert (= 1 (*)))))
 
 
 (setv test_sub (fn []
@@ -19,7 +21,9 @@
 
 (setv test_add (fn []
                  "NATIVE: Test addition"
-                 (assert (= 4 (+ 1 1 1 1)))))
+                 (assert (= 4 (+ 1 1 1 1)))
+                 (assert (= 8 (+ 8)))
+                 (assert (= 0 (+)))))
 
 
 (setv test_div (fn []
Repository: hylang/hy

Issue:
problem with comment parsing
I was translating some code to Hy from a textbook on Python programming (http://inventwithpython.com/pygame/index.html) and ran into a problem with this direct translation.

```
(import pygame sys)
(import [pygame.locals [*]])

(pygame.init)
(setv *displaysurf* (pygame.display.set_mode (, 400 300)))
(pygame.display.set_caption "Hello World!")
(while True ; main game loop
       (do (foreach [event (pygame.event.get)]
                    (if (= event.type QUIT)
                        (do (pygame.quit)
                            (sys.exit))))
           (pygame.display.update)))
```

I get a parse error if the end-of-line comment ("main game loop") appears where it does.  It works if I remove it.

The following interaction with the prompt also surprised me.

```
=> ; some comment
hy.lex.exceptions.LexException: Could not identify the next token at line -1, column -1
```

Fixing this isn't critical, but it should probably be fixed.  I do occasionally type something, realize I need to do something else first, comment it, press Enter, type whatever setup I needed, press Enter, then press Up twice, uncomment the line, and Enter to run it.

problem with comment parsing
I was translating some code to Hy from a textbook on Python programming (http://inventwithpython.com/pygame/index.html) and ran into a problem with this direct translation.

```
(import pygame sys)
(import [pygame.locals [*]])

(pygame.init)
(setv *displaysurf* (pygame.display.set_mode (, 400 300)))
(pygame.display.set_caption "Hello World!")
(while True ; main game loop
       (do (foreach [event (pygame.event.get)]
                    (if (= event.type QUIT)
                        (do (pygame.quit)
                            (sys.exit))))
           (pygame.display.update)))
```

I get a parse error if the end-of-line comment ("main game loop") appears where it does.  It works if I remove it.

The following interaction with the prompt also surprised me.

```
=> ; some comment
hy.lex.exceptions.LexException: Could not identify the next token at line -1, column -1
```

Fixing this isn't critical, but it should probably be fixed.  I do occasionally type something, realize I need to do something else first, comment it, press Enter, type whatever setup I needed, press Enter, then press Up twice, uncomment the line, and Enter to run it.



Discussion:

Resolving patch:
diff --git a/hy/lex/lexer.py b/hy/lex/lexer.py
--- a/hy/lex/lexer.py
+++ b/hy/lex/lexer.py
@@ -60,7 +60,7 @@
 lg.add('IDENTIFIER', r'[^()\[\]{}\'"\s;]+')
 
 
-lg.ignore(r';.*[\r\n]+')
+lg.ignore(r';.*(?=\r|\n|$)')
 lg.ignore(r'\s+')
 
 


Test patch:
diff --git a/tests/lex/test_lex.py b/tests/lex/test_lex.py
--- a/tests/lex/test_lex.py
+++ b/tests/lex/test_lex.py
@@ -260,3 +260,9 @@ def test_reader_macro():
     assert entry[0][0] == HySymbol("dispatch_reader_macro")
     assert entry[0][1] == HyExpression([HySymbol("quote"), HyString("^")])
     assert len(entry[0]) == 3
+
+
+def test_lex_comment_382():
+    """Ensure that we can tokenize sources with a comment at the end"""
+    entry = tokenize("foo ;bar\n;baz")
+    assert entry == [HySymbol("foo")]
Repository: hylang/hy

Issue:
Try to fix Travis
Take 1. It works locally on my laptop, but I still need to make sure Travis feels the same way.



Discussion:

Resolving patch:
diff --git a/hy/_compat.py b/hy/_compat.py
--- a/hy/_compat.py
+++ b/hy/_compat.py
@@ -52,3 +52,9 @@ def wr_long(f, x):
     long_type = int
 else:
     long_type = long  # NOQA
+
+if PY3:
+    exec('def raise_empty(t, *args): raise t(*args) from None')
+else:
+    def raise_empty(t, *args):
+        raise t(*args)
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -38,7 +38,7 @@
 from hy.errors import HyCompileError, HyTypeError
 
 import hy.macros
-from hy._compat import str_type, long_type, PY27, PY33, PY3, PY34
+from hy._compat import str_type, long_type, PY27, PY33, PY3, PY34, raise_empty
 from hy.macros import require, macroexpand, reader_macroexpand
 import hy.importer
 
@@ -429,7 +429,7 @@ def compile(self, tree):
         except HyTypeError as e:
             raise
         except Exception as e:
-            raise HyCompileError(e, sys.exc_info()[2])
+            raise_empty(HyCompileError, e, sys.exc_info()[2])
 
         raise HyCompileError(Exception("Unknown type: `%s'" % _type))
 


Test patch:
diff --git a/tests/test_bin.py b/tests/test_bin.py
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -26,8 +26,11 @@
 from hy._compat import PY3
 
 
+hy_dir = os.environ.get('HY_DIR', '')
+
+
 def run_cmd(cmd, stdin_data=None):
-    p = subprocess.Popen(cmd,
+    p = subprocess.Popen(os.path.join(hy_dir, cmd),
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
Repository: hylang/hy

Issue:
with-decorator on classes
with-decorator only accepts functions, not classes.  In Python you can apply decorators on both functions and classes.

An example in the standard library is `functools.total_ordering`

https://docs.python.org/3/library/functools.html#functools.total_ordering



Discussion:

Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -1268,7 +1268,8 @@ def compile_assoc_expression(self, expr):
     def compile_decorate_expression(self, expr):
         expr.pop(0)  # with-decorator
         fn = self.compile(expr.pop(-1))
-        if not fn.stmts or not isinstance(fn.stmts[-1], ast.FunctionDef):
+        if not fn.stmts or not (isinstance(fn.stmts[-1], ast.FunctionDef) or
+                                isinstance(fn.stmts[-1], ast.ClassDef)):
             raise HyTypeError(expr, "Decorated a non-function")
         decorators, ret = self._compile_collect(expr)
         fn.stmts[-1].decorator_list = decorators


Test patch:
diff --git a/tests/native_tests/with_decorator.hy b/tests/native_tests/with_decorator.hy
--- a/tests/native_tests/with_decorator.hy
+++ b/tests/native_tests/with_decorator.hy
@@ -7,6 +7,15 @@
     (* 2 2)))
 
 
+(defn bardec [cls]
+  (setv cls.my_attr 123))
+
+(with-decorator bardec
+  (defclass cls []
+    [[my_attr 456]]))
+
+
 (defn test-decorators []
   "NATIVE: test decorators."
-  (assert (= (tfunction) 2)))
+  (assert (= (tfunction) 2))
+  (assert (= cls.my_attr 123)))
Repository: hylang/hy

Issue:
Bad error message when defining function without parameter vector
Not sure if you want an issue for something like this but simply running

```
(defn function-without-params-vector "returnvalue")
```

in hy repl gives

```
HyCompileError: Internal Compiler Bug ­ƒÿ▒
ÔñÀ AttributeError: 'unicode' object has no attribute 'start_line'
Compilation traceback:
File "e:\dev\app\Python27\lib\site-packages\hy\compiler.py", line 420, in compile
```



Discussion:

Resolving patch:
diff --git a/hy/compiler.py b/hy/compiler.py
--- a/hy/compiler.py
+++ b/hy/compiler.py
@@ -1893,6 +1893,9 @@ def compile_function_def(self, expression):
         called_as = expression.pop(0)
 
         arglist = expression.pop(0)
+        if not isinstance(arglist, HyList):
+            raise HyTypeError(expression,
+                              "First argument to (fn) must be a list")
         ret, args, defaults, stararg, kwargs = self._parse_lambda_list(arglist)
 
         if PY34:


Test patch:
diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy
--- a/tests/native_tests/language.hy
+++ b/tests/native_tests/language.hy
@@ -52,6 +52,15 @@
   (try (eval '(defn lambda [] (print "hello")))
        (catch [e [TypeError]] (assert (in "Can't assign to a builtin" (str e))))))
 
+(defn test-fn-corner-cases []
+  "NATIVE: tests that fn/defn handles corner cases gracefully"
+  (try (eval '(fn "foo"))
+       (catch [e [Exception]] (assert (in "to (fn) must be a list"
+                                          (str e)))))
+  (try (eval '(defn foo "foo"))
+       (catch [e [Exception]]
+         (assert (in "takes a parameter list as second" (str e))))))
+
 (defn test-for-loop []
   "NATIVE: test for loops"
   (setv count 0)