nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jcrist/msgspec
Pull request #397 (2023-05-01 21:13:44)

Dedent docstrings
Strip leading whitespace from docstrings using [`textwrap.dedent()`](https://docs.python.org/3.11/library/textwrap.html?t#textwrap.dedent). This fixes markdown rendering of multiline docstrings.

Without this, the leading whitespace before each line causes markdown renderers to interpret the entire docstring as a code block, and inline formatting does not work.


Patch:
diff --git a/msgspec/_json_schema.py b/msgspec/_json_schema.py
index 9fd6fa0..da28a6d 100644
--- a/msgspec/_json_schema.py
+++ b/msgspec/_json_schema.py
@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import re
+import textwrap
 from collections.abc import Iterable
 from typing import Any
 
@@ -142,6 +143,7 @@ def _get_doc(t: mi.Type) -> str:
     doc = getattr(cls, "__doc__", "")
     if not doc:
         return ""
+    doc = textwrap.dedent(doc).strip("\r\n")
     if isinstance(t, mi.EnumType):
         if doc == "An enumeration.":
             return ""


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 87fec0d..badfbec 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -1159,3 +1159,27 @@ def test_ref_template():
             "required": ["b"],
         },
     }
+
+
+def test_multiline_docstring():
+    class Example(msgspec.Struct):
+        """
+            indented first line
+
+        last line.
+        """
+
+        pass
+
+    assert msgspec.json.schema(Example) == {
+        "$ref": "#/$defs/Example",
+        "$defs": {
+            "Example": {
+                "description": "    indented first line\n\nlast line.",
+                "title": "Example",
+                "type": "object",
+                "properties": {},
+                "required": [],
+            }
+        },
+    }
Repository: jcrist/msgspec
Pull request #604 (2023-12-07 17:42:53)

Pass key constraints as `propertyNames` in JSON Schema
This adds support for publicizing constraints on dict keys using the `propertyNames` field when generating a JSON Schema. For now this is only done for dicts with string keys; constraints on other key types are trickier to specify.

Supersedes #576.


Patch:
diff --git a/msgspec/_json_schema.py b/msgspec/_json_schema.py
index ab1c5e5..6a4fa94 100644
--- a/msgspec/_json_schema.py
+++ b/msgspec/_json_schema.py
@@ -271,6 +271,17 @@ def _to_schema(
             schema["items"] = False
     elif isinstance(t, mi.DictType):
         schema["type"] = "object"
+        # If there are restrictions on the keys, specify them as propertyNames
+        if isinstance(key_type := t.key_type, mi.StrType):
+            property_names = {}
+            if key_type.min_length is not None:
+                property_names["minLength"] = key_type.min_length
+            if key_type.max_length is not None:
+                property_names["maxLength"] = key_type.max_length
+            if key_type.pattern is not None:
+                property_names["pattern"] = key_type.pattern
+            if property_names:
+                schema["propertyNames"] = property_names
         if not isinstance(t.value_type, mi.AnyType):
             schema["additionalProperties"] = _to_schema(
                 t.value_type, name_map, ref_template


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 372263f..fbcfdd4 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -1073,6 +1073,23 @@ def test_string_metadata(field, val, constraint):
     assert msgspec.json.schema(typ) == {"type": "string", constraint: val}
 
 
+@pytest.mark.parametrize(
+    "field, val, constraint",
+    [
+        ("pattern", "[a-z]*", "pattern"),
+        ("min_length", 0, "minLength"),
+        ("max_length", 3, "maxLength"),
+    ],
+)
+def test_dict_key_metadata(field, val, constraint):
+    typ = Annotated[str, Meta(**{field: val})]
+    assert msgspec.json.schema(Dict[typ, int]) == {
+        "type": "object",
+        "additionalProperties": {"type": "integer"},
+        "propertyNames": {constraint: val},
+    }
+
+
 @pytest.mark.parametrize("typ", [bytes, bytearray])
 @pytest.mark.parametrize(
     "field, n, constraint",
Repository: jcrist/skein
Pull request #151 (2019-04-01 20:48:22)

Fix skein.properties.container_dir
Fixes a bug (introduced in 0.6.0) in detecting the absolute path to the
container directory.  YARN (at least some versions) will create all
possible container directories (as listed in
`yarn.nodemanager.local-dirs`, but only populate one of them. Previously
we were just looking for a directory to exist when searching for the
container directory, now we look for the proper files as well.


Patch:
diff --git a/skein/core.py b/skein/core.py
index 92a7340..64bec3f 100644
--- a/skein/core.py
+++ b/skein/core.py
@@ -81,7 +81,11 @@ class Properties(Mapping):
         if yarn_container_id is not None:
             for path in os.environ.get('LOCAL_DIRS', '').split(','):
                 check_dir = os.path.join(path, yarn_container_id)
-                if os.path.exists(check_dir):
+                # YARN will create all possible directories, but only populate
+                # one of them. We have to check that the files exist in the
+                # directory, rather than just that the directory exists.
+                if (os.path.exists(os.path.join(check_dir, '.skein.crt')) and
+                        os.path.exists(os.path.join(check_dir, '.skein.pem'))):
                     container_dir = check_dir
                     break
 


Test patch:
diff --git a/skein/test/test_core.py b/skein/test/test_core.py
index a2e6b3e..18c70a2 100644
--- a/skein/test/test_core.py
+++ b/skein/test/test_core.py
@@ -280,12 +280,13 @@ def test_appclient_and_security_in_container(monkeypatch, tmpdir, security):
     app_id = 'application_1526134340424_0012'
     container_id = 'container_1526134340424_0012_01_000005'
     address = 'edge.example.com:8765'
-    bad_dir = str(tmpdir.mkdir("nothing_in_here"))
+    bad_dir = tmpdir.mkdir("nothing_in_here")
+    bad_dir.mkdir(container_id)
 
     for key, val in [('SKEIN_APPLICATION_ID', app_id),
                      ('CONTAINER_ID', container_id),
                      ('SKEIN_APPMASTER_ADDRESS', address),
-                     ('LOCAL_DIRS', bad_dir)]:
+                     ('LOCAL_DIRS', str(bad_dir))]:
         monkeypatch.setenv(key, val)
 
     properties = Properties()