internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Textualize/rich

Issue:
Missing whitespace in traceback
In tracebacks sometimes there is a missing blank line between traceback frames. Not sure what causes it.


Discussion:
I'm still trying to reproduce the bug, but so far all the tracebacks I can display seem to be correctly formatted - (too) good job Rich! :sweat_smile: 
It's a weird one, doesn't always occur. It may be related to the number of frames. Try with 2 frames.
I checked with Darren, and I understand the issue now! Working on it :slightly_smiling_face: 

Resolving patch:
diff --git a/rich/traceback.py b/rich/traceback.py
--- a/rich/traceback.py
+++ b/rich/traceback.py
@@ -584,7 +584,7 @@ def render_locals(frame: Frame) -> Iterable[ConsoleRenderable]:
                 )
                 excluded = False
 
-            first = frame_index == 1
+            first = frame_index == 0
             frame_filename = frame.filename
             suppressed = any(frame_filename.startswith(path) for path in self.suppress)
 


Test patch:
diff --git a/tests/test_traceback.py b/tests/test_traceback.py
--- a/tests/test_traceback.py
+++ b/tests/test_traceback.py
@@ -1,4 +1,5 @@
 import io
+import re
 import sys
 
 import pytest
@@ -21,10 +22,17 @@
 def test_handler():
     console = Console(file=io.StringIO(), width=100, color_system=None)
     expected_old_handler = sys.excepthook
+
+    def level1():
+        level2()
+
+    def level2():
+        return 1 / 0
+
     try:
         old_handler = install(console=console)
         try:
-            1 / 0
+            level1()
         except Exception:
             exc_type, exc_value, traceback = sys.exc_info()
             sys.excepthook(exc_type, exc_value, traceback)
@@ -32,6 +40,30 @@ def test_handler():
             print(repr(rendered_exception))
             assert "Traceback" in rendered_exception
             assert "ZeroDivisionError" in rendered_exception
+
+            frame_blank_line_possible_preambles = (
+                # Start of the stack rendering:
+                "╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮",
+                # Each subsequent frame (starting with the file name) should then be preceded with a blank line:
+                "│" + (" " * 98) + "│",
+            )
+            for frame_start in re.finditer(
+                "^│ .+rich/tests/test_traceback\.py:",
+                rendered_exception,
+                flags=re.MULTILINE,
+            ):
+                frame_start_index = frame_start.start()
+                for preamble in frame_blank_line_possible_preambles:
+                    preamble_start, preamble_end = (
+                        frame_start_index - len(preamble) - 1,
+                        frame_start_index - 1,
+                    )
+                    if rendered_exception[preamble_start:preamble_end] == preamble:
+                        break
+                else:
+                    pytest.fail(
+                        f"Frame {frame_start[0]} doesn't have the expected preamble"
+                    )
     finally:
         sys.excepthook = old_handler
         assert old_handler == expected_old_handler
Repository: Textualize/rich

Issue:
[BUG] Tilde not included in link regex
The following doesn't highlight pas the `~`
```
>>> from rich import print
>>> print("http://127.0.0.1/~foo")
http://127.0.0.1/~foo
```




Discussion:
Thank you for your issue. Give us a little time to review it.

PS. You might want to check the [FAQ](https://github.com/textualize/rich/blob/master/FAQ.md) if you haven't done so already.

This is an automated reply, generated by [FAQtory](https://github.com/willmcgugan/faqtory)

Resolving patch:
diff --git a/rich/highlighter.py b/rich/highlighter.py
--- a/rich/highlighter.py
+++ b/rich/highlighter.py
@@ -98,7 +98,7 @@ class ReprHighlighter(RegexHighlighter):
             r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
             r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
             r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
-            r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#]*)",
+            r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~]*)",
         ),
     ]
 


Test patch:
diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py
--- a/tests/test_highlighter.py
+++ b/tests/test_highlighter.py
@@ -133,6 +133,16 @@ def test_wrong_type():
     (" https://example.org ", [Span(1, 20, "repr.url")]),
     (" http://example.org ", [Span(1, 19, "repr.url")]),
     (" http://example.org/index.html ", [Span(1, 30, "repr.url")]),
+    (" http://example.org/index.html#anchor ", [Span(1, 37, "repr.url")]),
+    (
+        " http://example.org/index.html?param1=value1 ",
+        [
+            Span(31, 37, "repr.attrib_name"),
+            Span(38, 44, "repr.attrib_value"),
+            Span(1, 44, "repr.url"),
+        ],
+    ),
+    (" http://example.org/~folder ", [Span(1, 27, "repr.url")]),
     ("No place like 127.0.0.1", [Span(14, 23, "repr.ipv4")]),
     ("''", [Span(0, 2, "repr.str")]),
     ("'hello'", [Span(0, 7, "repr.str")]),
Repository: Textualize/rich

Issue:
[BUG] `Panel.fit` forgot `height` and `highlight` parameters
- [x] I've checked [docs](https://rich.readthedocs.io/en/latest/introduction.html) and [closed issues](https://github.com/Textualize/rich/issues?q=is%3Aissue+is%3Aclosed) for possible solutions.
- [x] I can't find my issue in the [FAQ](https://github.com/Textualize/rich/blob/master/FAQ.md).

**Describe the bug**

`Panel.fit` forgot `height` and `highlight` parameters. It should be updated to synchronize with the constructor.

```python
class Panel(JupyterMixin):
    def __init__(
        self,
        renderable: "RenderableType",
        box: Box = ROUNDED,
        *,
        title: Optional[TextType] = None,
        title_align: AlignMethod = "center",
        subtitle: Optional[TextType] = None,
        subtitle_align: AlignMethod = "center",
        safe_box: Optional[bool] = None,
        expand: bool = True,
        style: StyleType = "none",
        border_style: StyleType = "none",
        width: Optional[int] = None,
        height: Optional[int] = None,
        padding: PaddingDimensions = (0, 1),
        highlight: bool = False,
    ) -> None:
        ...

    @classmethod
    def fit(
        cls,
        renderable: "RenderableType",
        box: Box = ROUNDED,
        *,
        title: Optional[TextType] = None,
        title_align: AlignMethod = "center",
        subtitle: Optional[TextType] = None,
        subtitle_align: AlignMethod = "center",
        safe_box: Optional[bool] = None,
        style: StyleType = "none",
        border_style: StyleType = "none",
        width: Optional[int] = None,
        padding: PaddingDimensions = (0, 1),
    ) -> "Panel":
        ...
```


Discussion:
Thank you for your issue. Give us a little time to review it.

PS. You might want to check the [FAQ](https://github.com/textualize/rich/blob/master/FAQ.md) if you haven't done so already.

This is an automated reply, generated by [FAQtory](https://github.com/willmcgugan/faqtory)

Resolving patch:
diff --git a/rich/panel.py b/rich/panel.py
--- a/rich/panel.py
+++ b/rich/panel.py
@@ -82,7 +82,9 @@ def fit(
         style: StyleType = "none",
         border_style: StyleType = "none",
         width: Optional[int] = None,
+        height: Optional[int] = None,
         padding: PaddingDimensions = (0, 1),
+        highlight: bool = False,
     ) -> "Panel":
         """An alternative constructor that sets expand=False."""
         return cls(
@@ -96,7 +98,9 @@ def fit(
             style=style,
             border_style=border_style,
             width=width,
+            height=height,
             padding=padding,
+            highlight=highlight,
             expand=False,
         )
 


Test patch:
Repository: Textualize/rich

Issue:
Export `rich.text.TextType` so it shows up in the reference
Exporting `TextType` and making it visible in the docs means we'll be able to link to it from the Textual docs, where it shows up _a lot_.


Discussion:
Thank you for your issue. Give us a little time to review it.

PS. You might want to check the [FAQ](https://github.com/textualize/rich/blob/master/FAQ.md) if you haven't done so already.

This is an automated reply, generated by [FAQtory](https://github.com/willmcgugan/faqtory)
@rodrigogiraoserrao I think this is done. Please check and close if it is.
I don't think it is.
`TextType` in `rich/text.py` _is_ documented with a docstring but it doesn't show up in the rich documentation online: https://rich.readthedocs.io/en/stable/reference/text.html

It's also not linked to from the Textual docs.
E.g., in the `Button` reference the table with its parameters mentions the `TextType` but doesn't link to it: https://textual.textualize.io/widgets/button/#textual.widgets.Button

The rich docs may need to be rebuilt.
I don't know how these docs work but maybe we need to add `TextStyle` to `rich/docs/source/reference/text.rst`:

https://github.com/Textualize/rich/blob/fd981823644ccf50d685ac9c0cfe8e1e56c9dd35/docs/source/reference/text.rst?plain=1#L1-L5

Resolving patch:
diff --git a/rich/text.py b/rich/text.py
--- a/rich/text.py
+++ b/rich/text.py
@@ -38,7 +38,7 @@
 _re_whitespace = re.compile(r"\s+$")
 
 TextType = Union[str, "Text"]
-"""A plain string or a [Text][rich.text.Text] instance."""
+"""A plain string or a :class:`Text` instance."""
 
 GetStyleCallable = Callable[[str], Optional[StyleType]]
 


Test patch:
Repository: facebookresearch/dynabench

Issue:
FLORES task 2 is showing Sundanese, but it's not part of the final release
Let's just remove the mention of it
<img width="715" alt="Screen Shot " src="https://user-images.githubusercontent.com/1409486/123301286-5b00d780-d4d0-11eb-8dcf-55b5d78ca870.png">



Discussion:
@TristanThrush I believe the description needs to be updated in the DB. 
Yes. This should be done in a yoyo db migration in a PR. Examples of migrations are in the api/migrations directory.

Resolving patch:
diff --git a/api/migrations/20210706_01_a9a26-fix-flores-description.py b/api/migrations/20210706_01_a9a26-fix-flores-description.py
new file mode 100644
--- /dev/null
+++ b/api/migrations/20210706_01_a9a26-fix-flores-description.py
@@ -0,0 +1,14 @@
+# Copyright (c) Facebook, Inc. and its affiliates.
+
+"""Fix the Flores description."""
+
+from yoyo import step
+
+
+__depends__ = {"20210503_01_xxxx-add-flores-task"}
+
+
+fix_desc = """Machine Translation Evaluation East Asian languages:
+Javanese, Indonesian, Malay, Tagalog, Tamil, English"""
+
+steps = [step(f'UPDATE tasks SET `desc`="{fix_desc}" WHERE task_code="flores_small2"')]


Test patch:
Repository: facebookresearch/dynabench

Issue:
Creating a task with the "Task Code" as a number doesn't work as expected.
After creating a task with the task code as a number, and accepting the task, when users want to navigate to the task, it should ideally take us to a page which says "The task owner still needs to activate this task.", but in this case, we are shown the respective page for a millisecond, and taken back to the home page, which I think is unexpected behaviour.

A demonstration is given in the following screen recording of the same issue.

**Steps to reproduce**:
- Create a task proposal with the "Task Code" field as a number
- Accept the task as the admin user.
- Now try to click on the respective task from your "Tasks" page. It should just take you back to the homepage.

This seems to happen only for a purely numeric "Task Code" and not for an alphanumeric "Task Code"

https://user-images.githubusercontent.com/48560219/135757335-d98f116f-b7d6-44dc-a1fd-0c8b6fac7c61.mov




Discussion:
Thanks for pointing this out! It would also be good to have a little explanation for what task code actually is. Maybe something like: this is a short string that will be the url for your task; e.g, "nli" for "Natural Language Inference"
The fix is probably to disallow any task code that doesn't contain at least one letter?
> Thanks for pointing this out! It would also be good to have a little explanation for what task code actually is. Maybe something like: this is a short string that will be the url for your task; e.g, "nli" for "Natural Language Inference"

Yeah, that makes a lot of sense. I could probably work on implementing the fixes.

Resolving patch:
diff --git a/api/controllers/task_proposals.py b/api/controllers/task_proposals.py
--- a/api/controllers/task_proposals.py
+++ b/api/controllers/task_proposals.py
@@ -66,11 +66,13 @@ def create_task_proposal(credentials):
     if tm.getByName(data["name"]):
         bottle.abort(400, "Invalid name; this name is already taken")
 
-    if not bool(re.search("^[a-zA-Z0-9_-]*$", data["task_code"])):
+    if not bool(
+        re.search("(?=^[a-zA-Z0-9_-]*$)(?=.*[a-zA-Z].*).*$", data["task_code"])
+    ):
         bottle.abort(
             400,
             "Invalid task code (no special characters allowed besides underscores "
-            + "and dashes)",
+            + "and dashes. At least one letter required)",
         )
 
     try:


Test patch:
Repository: encode/starlette

Issue:
CORSMiddleware is sending an extra 'http.response.body'
It seems that even with all tests passing and cors being successfully applied, CORSMiddleware still raises a runtime error.

Code being tested:
```python
app = Starlette()

app.add_middleware(CORSMiddleware, allow_origins=["*"])

@app.route("/")
async def homepage(request):
    return PlainTextResponse('Hello', status_code=200)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)
```

And the error being produced:
```
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/home/alexbotello/.local/share/virtualenvs/starlette-dshJy1CJ/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 384, in run_asgi
    result = await asgi(self.receive, self.send)
  File "/home/alexbotello/Code/starlette/starlette/exceptions.py", line 60, in app
    raise exc from None
  File "/home/alexbotello/Code/starlette/starlette/exceptions.py", line 52, in app
    await instance(receive, sender)
  File "/home/alexbotello/Code/starlette/starlette/middleware/cors.py", line 116, in simple_response
    await inner(receive, send)
  File "/home/alexbotello/Code/starlette/starlette/applications.py", line 26, in awaitable
    await response(receive, send)
  File "/home/alexbotello/Code/starlette/starlette/responses.py", line 100, in __call__
    await send({"type": "http.response.body", "body": self.body})
  File "/home/alexbotello/Code/starlette/starlette/middleware/cors.py", line 130, in send
    await send(message)
  File "/home/alexbotello/Code/starlette/starlette/exceptions.py", line 47, in sender
    await send(message)
  File "/home/alexbotello/.local/share/virtualenvs/starlette-dshJy1CJ/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 518, in send
    raise RuntimeError(msg % message_type)
RuntimeError: Unexpected ASGI message 'http.response.body' sent, after response already completed.
```
It seems the issue is originating from `send`. Specifically:
```python
if message["type"] != "http.response.start":
    await send(message)
```
Removing this fixes the issue and does not break any tests.


Discussion:

Resolving patch:
diff --git a/starlette/middleware/cors.py b/starlette/middleware/cors.py
--- a/starlette/middleware/cors.py
+++ b/starlette/middleware/cors.py
@@ -118,6 +118,7 @@ async def simple_response(self, receive, send, scope=None, origin=None):
     async def send(self, message, send=None, origin=None):
         if message["type"] != "http.response.start":
             await send(message)
+            return
 
         message.setdefault("headers", [])
         headers = MutableHeaders(message["headers"])


Test patch:
Repository: encode/starlette

Issue:
scope["server"] can be None
From https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope

> server: A two-item iterable of [host, port], where host is the listening address for this server as a unicode string, and port is the integer listening port. Optional, defaults to None.

https://github.com/encode/starlette/blob/master/starlette/datastructures.py#L11 doesn't handle that option, it assumes scope["server"] is always a two-pair




Discussion:

Resolving patch:
diff --git a/starlette/datastructures.py b/starlette/datastructures.py
--- a/starlette/datastructures.py
+++ b/starlette/datastructures.py
@@ -7,16 +7,20 @@ class URL:
     def __init__(self, url: str = "", scope: Scope = None) -> None:
         if scope is not None:
             assert not url, 'Cannot set both "url" and "scope".'
-            scheme = scope["scheme"]
-            host, port = scope["server"]
+            scheme = scope.get("scheme", "http")
+            server = scope.get("server", None)
             path = scope.get("root_path", "") + scope["path"]
             query_string = scope["query_string"]
 
-            default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}[scheme]
-            if port == default_port:
-                url = "%s://%s%s" % (scheme, host, path)
+            if server is None:
+                url = path
             else:
-                url = "%s://%s:%s%s" % (scheme, host, port, path)
+                host, port = server
+                default_port = {"http": 80, "https": 443, "ws": 80, "wss": 443}[scheme]
+                if port == default_port:
+                    url = "%s://%s%s" % (scheme, host, path)
+                else:
+                    url = "%s://%s:%s%s" % (scheme, host, port, path)
 
             if query_string:
                 url += "?" + unquote(query_string.decode())
@@ -85,6 +89,9 @@ def __eq__(self, other):
     def __str__(self):
         return self._url
 
+    def __repr__(self):
+        return "%s(%s)" % (self.__class__.__name__, repr(self._url))
+
 
 # Type annotations for valid `__init__` values to QueryParams and Headers.
 StrPairs = typing.Sequence[typing.Tuple[str, str]]


Test patch:
diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py
--- a/tests/test_datastructures.py
+++ b/tests/test_datastructures.py
@@ -27,6 +27,23 @@ def test_url():
     assert new.hostname == "example.com"
 
 
+def test_url_from_scope():
+    u = URL(scope={"path": "/path/to/somewhere", "query_string": b"abc=123"})
+    assert u == "/path/to/somewhere?abc=123"
+    assert repr(u) == "URL('/path/to/somewhere?abc=123')"
+
+    u = URL(
+        scope={
+            "scheme": "https",
+            "server": ("example.org", 123),
+            "path": "/path/to/somewhere",
+            "query_string": b"abc=123",
+        }
+    )
+    assert u == "https://example.org:123/path/to/somewhere?abc=123"
+    assert repr(u) == "URL('https://example.org:123/path/to/somewhere?abc=123')"
+
+
 def test_headers():
     h = Headers([(b"a", b"123"), (b"a", b"456"), (b"b", b"789")])
     assert "a" in h
Repository: encode/starlette

Issue:
Form field names do not escape perfect encoding
I switched one microservice from Flask to Starlette and got unexpected form parsing problem.
This code will return %20 in places where spaces were supposed to be:
```
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.requests import Request as StarletteRequest

SERVER = Starlette()

@SERVER.route("/send", methods=["POST"])
async def send_endpoint(request: StarletteRequest) -> PlainTextResponse:
    form = await request.form()
    if "number" in form and "name" in form:
        number = form["number"]
        name = form["name"]
        return PlainTextResponse("Number: " + number + " ; Name: " + name)
```

Maybe there are other issues with form parsing (x-www-form-urlencoded).


Discussion:
Hmm, this seems to be an issue with the `FormParser` class. I think this is easily fixed if we call `urllib.parse.unquote` on the decoded field value.

I'll submit a PR fixing this

Resolving patch:
diff --git a/starlette/formparsers.py b/starlette/formparsers.py
--- a/starlette/formparsers.py
+++ b/starlette/formparsers.py
@@ -1,9 +1,11 @@
-from enum import Enum
-from starlette.datastructures import Headers
-import asyncio
 import io
-import tempfile
 import typing
+import asyncio
+import tempfile
+from enum import Enum
+from urllib.parse import unquote
+
+from starlette.datastructures import Headers
 
 try:
     from multipart.multipart import parse_options_header
@@ -69,27 +71,22 @@ def __init__(
         self.messages = []  # type: typing.List[typing.Tuple[FormMessage, bytes]]
 
     def on_field_start(self) -> None:
-        print("on_field_start")
         message = (FormMessage.FIELD_START, b"")
         self.messages.append(message)
 
     def on_field_name(self, data: bytes, start: int, end: int) -> None:
-        print("on_field_name")
         message = (FormMessage.FIELD_NAME, data[start:end])
         self.messages.append(message)
 
     def on_field_data(self, data: bytes, start: int, end: int) -> None:
-        print("on_field_data")
         message = (FormMessage.FIELD_DATA, data[start:end])
         self.messages.append(message)
 
     def on_field_end(self) -> None:
-        print("on_field_end")
         message = (FormMessage.FIELD_END, b"")
         self.messages.append(message)
 
     def on_end(self) -> None:
-        print("on_end")
         message = (FormMessage.END, b"")
         self.messages.append(message)
 
@@ -127,7 +124,9 @@ async def parse(self) -> typing.Dict[str, typing.Union[str, UploadFile]]:
                 elif message_type == FormMessage.FIELD_DATA:
                     field_value += message_bytes
                 elif message_type == FormMessage.FIELD_END:
-                    result[field_name.decode("latin-1")] = field_value.decode("latin-1")
+                    result[field_name.decode("latin-1")] = unquote(
+                        field_value.decode("latin-1")
+                    )
                 elif message_type == FormMessage.END:
                     pass
 


Test patch: