Northy1717/SWE-bench-Live huggingface dataset:
Repository: quantumlib/Cirq

Issue:
Crash when printing circuit with controlled MatrixGate
## Describe the issue

Cirq crashes when printing a circuit that contains a controlled 1x1 MatrixGate

## Explain how to reproduce the bug or problem

```python
    q = cirq.LineQubit(0)
    g = cirq.MatrixGate(np.array([[1j]])).controlled()
    c = cirq.Circuit(g(q))
    print(c)
```

hits `raise ValueError(f'Wanted diagram info from {op!r} for {rows!r}) but got {info!r}')`.


## Tell us the version of Cirq where this happens

1.4.1


Discussion:
What's the expected result?
Probably something like `q:  ----C(Matrix[1j])----`.
Oh, turns out this happens for non controlled 1x1 matrices too. So it has nothing to do with being controlled. It's probably the same issue as https://github.com/quantumlib/Cirq/issues/5944, so the fix would be similar to the PR that's linked to it. Just return early if the gate has no qubits. 



Patch:
diff --git a/cirq-core/cirq/ops/matrix_gates.py b/cirq-core/cirq/ops/matrix_gates.py
index 5ac9385e3b6..a2cb8707a44 100644
--- a/cirq-core/cirq/ops/matrix_gates.py
+++ b/cirq-core/cirq/ops/matrix_gates.py
@@ -187,6 +187,9 @@ def _circuit_diagram_info_(
         self, args: 'cirq.CircuitDiagramInfoArgs'
     ) -> 'cirq.CircuitDiagramInfo':
         n_qubits = len(self._qid_shape)
+        # No diagram for zero-qubit gates; let fallback handle it
+        if n_qubits == 0:
+            return NotImplemented
         if self._name is not None:
             symbols = (
                 [self._name] if n_qubits == 1 else [f'{self._name}[{i+1}]' for i in range(n_qubits)]


Test patch:
diff --git a/cirq-core/cirq/protocols/circuit_diagram_info_protocol_test.py b/cirq-core/cirq/protocols/circuit_diagram_info_protocol_test.py
index 23198efea01..17ec4b5c24f 100644
--- a/cirq-core/cirq/protocols/circuit_diagram_info_protocol_test.py
+++ b/cirq-core/cirq/protocols/circuit_diagram_info_protocol_test.py
@@ -115,6 +115,13 @@ def _circuit_diagram_info_(self, args):
     assert cirq.circuit_diagram_info(E()) == cirq.CircuitDiagramInfo(('X',))
 
 
+def test_controlled_1x1_matrixgate_diagram_error():
+    q = cirq.LineQubit(0)
+    g = cirq.MatrixGate(np.array([[1j]])).controlled()
+    c = cirq.Circuit(g(q))
+    assert str(c) == "0: ───C[[0.+1.j]]───"
+
+
 def test_circuit_diagram_info_args_eq():
     eq = cirq.testing.EqualsTester()
     eq.add_equality_group(cirq.CircuitDiagramInfoArgs.UNINFORMED_DEFAULT)
Repository: sissbruecker/linkding

Issue:
Make hyperlinks clickable in notes without special markdown syntax
Some markdown flavors parse links event without the hyperlink syntax `[https://github.com](https://github.com)`. Is this possible to implement with the markdown parser that you use for the description/notes input?


Discussion:
Not an exact solution, but if you just want a shorter syntax for links, you can do:

```
<https://github.com/>
```
Oh thank you, I wasn't aware of that markdown syntax.
This is what linkding uses: https://python-markdown.github.io/

Doesn't look like there is an existing extension for that.
Looks like there are some third party extensions that may do the trick if you're interested: https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions#url-conversion. I think this could be valuable shorthand to provide additional links as context to each bookmark.

Related: https://github.com/Python-Markdown/markdown/issues/789



Patch:
diff --git a/bookmarks/templatetags/shared.py b/bookmarks/templatetags/shared.py
index 5da3c1c3..297c453d 100644
--- a/bookmarks/templatetags/shared.py
+++ b/bookmarks/templatetags/shared.py
@@ -142,5 +142,6 @@ def render_markdown(context, markdown_text):
 
     as_html = renderer.convert(markdown_text)
     sanitized_html = bleach.clean(as_html, markdown_tags, markdown_attrs)
+    linkified_html = bleach.linkify(sanitized_html)
 
-    return mark_safe(sanitized_html)
+    return mark_safe(linkified_html)


Test patch:
diff --git a/bookmarks/tests/test_bookmarks_list_template.py b/bookmarks/tests/test_bookmarks_list_template.py
index 46ed2903..802ae456 100644
--- a/bookmarks/tests/test_bookmarks_list_template.py
+++ b/bookmarks/tests/test_bookmarks_list_template.py
@@ -884,6 +884,21 @@ def test_note_renders_markdown(self):
         )
         self.assertNotes(html, note_html, 1)
 
+    def test_note_renders_markdown_with_linkify(self):
+        # Should linkify plain URL
+        self.setup_bookmark(notes="Example: https://example.com")
+        html = self.render_template()
+
+        note_html = '<p>Example: <a href="https://example.com" rel="nofollow">https://example.com</a></p>'
+        self.assertNotes(html, note_html, 1)
+
+        # Should not linkify URL in markdown link
+        self.setup_bookmark(notes="[https://example.com](https://example.com)")
+        html = self.render_template()
+
+        note_html = '<p><a href="https://example.com" rel="nofollow">https://example.com</a></p>'
+        self.assertNotes(html, note_html, 1)
+
     def test_note_cleans_html(self):
         self.setup_bookmark(notes='<script>alert("test")</script>')
         self.setup_bookmark(
Repository: matplotlib/matplotlib

Issue:
`ax.pie()` raises `ValueError` when input contains `NaN`
- **Description**: When using `matplotlib.pyplot.pie()` with a list that includes a `NaN`, the function raises a `ValueError`. This crash is not currently caught or documented.

```
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
data = [10, 20, float('nan'), 40]
ax.pie(data, labels=["A", "B", "C", "D"])
plt.show()
```

- **Error Message**
`ValueError: cannot convert float NaN to integer`

- **Expected Behavior** - `matplotlib.pie()` should either: Filter out`NaNs`, or raise a clear and user-friendly `ValueError`

- **Environment:**
  - Python: 3.11

  - Matplotlib: 3.8.x
  
  - OS: Windows 10
  
  - Found via: Fuzz testing


[@tacaswell edited to fix markdown markup]


Discussion:
Given that we re-scale the data passed in we should do an `np.isfinite` check in `ax.pie` and raise if nan (or inf) comes in.

We already do a check for negative values and some other validity checks https://github.com/matplotlib/matplotlib/blob/9f0cdfd45daad4865a8505b4fba4234346586fbe/lib/matplotlib/axes/_axes.py#L3299-L3305

would you be interested in working on this @34wizrd ?



Patch:
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index b46cbce39c58..81ebd7267ece 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -3303,6 +3303,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
         if np.any(x < 0):
             raise ValueError("Wedge sizes 'x' must be non negative values")
 
+        if not np.all(np.isfinite(x)):
+            raise ValueError('Wedge sizes must be finite numbers')
+
         sx = x.sum()
 
         if normalize:


Test patch:
diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py
index 70d1671cafa3..9c13ce76b2e2 100644
--- a/lib/matplotlib/tests/test_axes.py
+++ b/lib/matplotlib/tests/test_axes.py
@@ -9720,3 +9720,11 @@ def test_bar_shape_mismatch():
     )
     with pytest.raises(ValueError, match=error_message):
         plt.bar(x, height)
+
+
+def test_pie_non_finite_values():
+    fig, ax = plt.subplots()
+    df = [5, float('nan'), float('inf')]
+
+    with pytest.raises(ValueError, match='Wedge sizes must be finite numbers'):
+        ax.pie(df, labels=['A', 'B', 'C'])
Repository: lektor/lektor

Issue:
Bug: `build_url` may remove trailing slash
Found this while browsing through the source. Havent tested whether this is actually an issue, but:

https://github.com/lektor/lektor/blob/dbae91e9c767093349b122f62e114e32e8291f85/lektor/utils.py#L666-L668

shouldn't that actually be
```py
last = url.split("/")[-1]
# or:
# if "." in url.split("/")[-1]:
```

Otherwise, an URL like this `/path.my/page/2/` may wrongly remove the trailing slash.


Discussion:
I think you're right about the `split`.

It was probably meant to be
```py
_, last = url.rsplit("/", 1)
```

Personally, I'd write it:
```py
_, _, last = url.rpartition("/")
```

(Perhaps a larger refactor/cleanup is possible.  Maybe using `pathlib.PurePosixPath`?)

As you say, it would be nice to have an actual test/demo of how it can go wrong.





Patch:
diff --git a/lektor/utils.py b/lektor/utils.py
index 9cbcd9aba..a518f0054 100644
--- a/lektor/utils.py
+++ b/lektor/utils.py
@@ -827,8 +827,9 @@ def get_url(self, trailing_slash=None):
         if url == "/":
             return url
         if trailing_slash is None:
-            _, last = url.split("/", 1)
+            _, last = url.rsplit("/", 1)
             if "." in last:
+                # Assuming the url points to a file
                 return url
         return url + "/"
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 04ea966bc..733880495 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -197,6 +197,10 @@ def test_url_builder():
     assert build_url(["a", None, "b", "", "c"]) == "/a/b/c/"
 
 
+def test_url_builder_dot_handling():
+    assert build_url(["blog", "01.01.2025", "photos"]) == "/blog/01.01.2025/photos/"
+
+
 def test_parse_path():
     assert parse_path("") == []
     assert parse_path("/") == []