nebius/SWE-bench-extra huggingface dataset:
Repository: iodevs/pyresult

Issue:
Operator `and_then` should returns error if passed function raise exception
* PyResult version: 0.8.0
* Python version: ANY
* Operating System: ANY

### Description

When function in `and_then` operator raise excpetion, then `and_then` function fail with exception, instead error result.

### What I Did

```python
from pyresult import and_then, ok

def raise_exception(val):
    raise Exception()

and_then(raise_exception, ok(1))

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-46-f0756160f235> in <module>()
----> 1 and_then(raise_exception, ok(1))

/usr/local/opt/pyenv/versions/3.6.2/envs/pydecoder/lib/python3.6/site-packages/toolz/functoolz.py in __call__(self, *args, **kwargs)
    281     def __call__(self, *args, **kwargs):
    282         try:
--> 283             return self._partial(*args, **kwargs)
    284         except TypeError as exc:
    285             if self._should_curry(args, kwargs, exc):

/usr/local/opt/pyenv/versions/3.6.2/envs/pydecoder/lib/python3.6/site-packages/pyresult/operators.py in and_then(func, res)
     40     '''
     41     res = result(res)
---> 42     return result(func(res.value)) if is_ok(res) else res
     43
     44

<ipython-input-43-6bead73ba782> in raise_exception(val)
      1 def raise_exception(val):
----> 2     raise Exception()
```

Look at iodevs/pydecoder#32

Comments:

Patch:
diff --git a/pyresult/operators.py b/pyresult/operators.py
index f8dd187..e045449 100644
--- a/pyresult/operators.py
+++ b/pyresult/operators.py
@@ -39,8 +39,11 @@ def and_then(func, res):
 
     and_then: (a -> Result b x) -> Result a x -> Result b x
     '''
-    res = result(res)
-    return result(func(res.value)) if is_ok(res) else res
+    try:
+        res = result(res)
+        return result(func(res.value)) if is_ok(res) else res
+    except Exception as e:
+        return error(str(e))
 
 
 @curry


Test patch:
diff --git a/tests/test_operators.py b/tests/test_operators.py
index 1f625d2..917334d 100644
--- a/tests/test_operators.py
+++ b/tests/test_operators.py
@@ -61,6 +61,13 @@ def test_and_then_is_ok():
     assert and_then(f, ok(val)) == (OK, val + 1)
 
 
+def test_and_then_catches_exception():
+    def raise_exception(val):
+        raise Exception("test")
+
+    assert and_then(raise_exception, ok(1)) == error("test")
+
+
 def test_and_then_original_res():
     val = (ERROR, 'msg')
Repository: ipython/ipython

Issue:
End of multiline string that contains a backslash-terminated line is not recognized
IPython 5.0/PTK1.0.5 does not recognize that

```
"""
foo\
bar
"""
```

is a full string and that it should execute the typed-in string after that point.


Comments:

Patch:
diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py
index 9036add8a..3fdc64160 100644
--- a/IPython/core/inputtransformer.py
+++ b/IPython/core/inputtransformer.py
@@ -120,25 +120,18 @@ class TokenInputTransformer(InputTransformer):
     """
     def __init__(self, func):
         self.func = func
-        self.current_line = ""
-        self.line_used = False
+        self.buf = []
         self.reset_tokenizer()
-    
+
     def reset_tokenizer(self):
-        self.tokenizer = generate_tokens(self.get_line)
-    
-    def get_line(self):
-        if self.line_used:
-            raise TokenError
-        self.line_used = True
-        return self.current_line
-    
+        it = iter(self.buf)
+        self.tokenizer = generate_tokens(it.__next__)
+
     def push(self, line):
-        self.current_line += line + "\n"
-        if self.current_line.isspace():
+        self.buf.append(line + '\n')
+        if all(l.isspace() for l in self.buf):
             return self.reset()
-        
-        self.line_used = False
+
         tokens = []
         stop_at_NL = False
         try:
@@ -158,13 +151,13 @@ def push(self, line):
         return self.output(tokens)
     
     def output(self, tokens):
-        self.current_line = ""
+        self.buf.clear()
         self.reset_tokenizer()
         return untokenize(self.func(tokens)).rstrip('\n')
     
     def reset(self):
-        l = self.current_line
-        self.current_line = ""
+        l = ''.join(self.buf)
+        self.buf.clear()
         self.reset_tokenizer()
         if l:
             return l.rstrip('\n')


Test patch:
diff --git a/IPython/core/tests/test_inputtransformer.py b/IPython/core/tests/test_inputtransformer.py
index 27e67d8dd..2aa0670d5 100644
--- a/IPython/core/tests/test_inputtransformer.py
+++ b/IPython/core/tests/test_inputtransformer.py
@@ -389,6 +389,11 @@ def test_assemble_python_lines():
        (u"2,", None),
        (None, u"a = [1,\n2,"),
       ],
+      [(u"a = '''", None),  # Test line continuation within a multi-line string
+       (u"abc\\", None),
+       (u"def", None),
+       (u"'''", u"a = '''\nabc\\\ndef\n'''"),
+      ],
     ] + syntax_ml['multiline_datastructure']
     for example in tests:
         transform_checker(example, ipt.assemble_python_lines)
Repository: ipython/ipython

Issue:
completer latex_matches no respecting API
It return matched text even if it return no completions.

Comments:

Patch:
diff --git a/IPython/core/completer.py b/IPython/core/completer.py
index 01730fff2..9091ccad5 100644
--- a/IPython/core/completer.py
+++ b/IPython/core/completer.py
@@ -1708,8 +1708,6 @@ def latex_matches(self, text):
         u"""Match Latex syntax for unicode characters.
 
         This does both ``\\alp`` -> ``\\alpha`` and ``\\alpha`` -> ``α``
-
-        Used on Python 3 only.
         """
         slashpos = text.rfind('\\')
         if slashpos > -1:
@@ -1722,7 +1720,8 @@ def latex_matches(self, text):
                 # If a user has partially typed a latex symbol, give them
                 # a full list of options \al -> [\aleph, \alpha]
                 matches = [k for k in latex_symbols if k.startswith(s)]
-                return s, matches
+                if matches:
+                    return s, matches
         return u'', []
 
     def dispatch_custom_completer(self, text):


Test patch:
diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py
index 2920d4539..2c19e2e01 100644
--- a/IPython/core/tests/test_completer.py
+++ b/IPython/core/tests/test_completer.py
@@ -224,20 +224,27 @@ def test_latex_completions(self):
         nt.assert_in("\\alpha", matches)
         nt.assert_in("\\aleph", matches)
 
+    def test_latex_no_results(self):
+        """
+        forward latex should really return nothing in either field if nothing is found.
+        """
+        ip = get_ipython()
+        text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
+        nt.assert_equal(text, "")
+        nt.assert_equal(matches, [])
+
     def test_back_latex_completion(self):
         ip = get_ipython()
 
         # do not return more than 1 matches fro \beta, only the latex one.
         name, matches = ip.complete("\\β")
-        nt.assert_equal(len(matches), 1)
-        nt.assert_equal(matches[0], "\\beta")
+        nt.assert_equal(matches, ['\\beta'])
 
     def test_back_unicode_completion(self):
         ip = get_ipython()
 
         name, matches = ip.complete("\\Ⅴ")
-        nt.assert_equal(len(matches), 1)
-        nt.assert_equal(matches[0], "\\ROMAN NUMERAL FIVE")
+        nt.assert_equal(matches, ["\\ROMAN NUMERAL FIVE"])
 
     def test_forward_unicode_completion(self):
         ip = get_ipython()