nebius/SWE-bench-extra huggingface dataset:
Repository: jd/tenacity

Issue:
retry doesn't pass retry_state to method
When using a bound method as a 'before' function (possibly others) that takes retry_state causes an error:


```    @_utils.wraps(fn)
    def wrapped_before_func(retry_state):
        # func, trial_number, trial_time_taken
        warn_about_non_retry_state_deprecation('before', fn, stacklevel=4)
        return fn(
            retry_state.fn,
>           retry_state.attempt_number,
        )
E       TypeError: _retry_refresh_token() takes 2 positional arguments but 3 were given
```

2 positional arguments above are self, retry_state

calling ```inspect.isfunction()``` on a bound method returns false, but then the code assumes it's a callable object. In result the compatibility wrapper is used which tries to call the method with parameters for the old-style before function.

https://github.com/jd/tenacity/blob/5f3d822c22ef435a57081a314bcb61b1c9f7b326/tenacity/compat.py#L29


Comments:

Patch:
diff --git a/tenacity/compat.py b/tenacity/compat.py
index 2d3e301..0451b8c 100644
--- a/tenacity/compat.py
+++ b/tenacity/compat.py
@@ -25,9 +25,10 @@ def warn_about_dunder_non_retry_state_deprecation(fn, stacklevel):
 
 def func_takes_retry_state(func):
     if not six.callable(func):
+        raise Exception(func)
         return False
-    if not inspect.isfunction(func):
-        # func is a callable object rather than a function
+    if not inspect.isfunction(func) and not inspect.ismethod(func):
+        # func is a callable object rather than a function/method
         func = func.__call__
     func_spec = _utils.getargspec(func)
     return 'retry_state' in func_spec.args
@@ -86,7 +87,7 @@ def func_takes_last_result(waiter):
     """
     if not six.callable(waiter):
         return False
-    if not inspect.isfunction(waiter):
+    if not inspect.isfunction(waiter) and not inspect.ismethod(waiter):
         # waiter is a class, check dunder-call rather than dunder-init.
         waiter = waiter.__call__
     waiter_spec = _utils.getargspec(waiter)


Test patch:
diff --git a/tenacity/tests/test_tenacity.py b/tenacity/tests/test_tenacity.py
index d3090fa..af96f3a 100644
--- a/tenacity/tests/test_tenacity.py
+++ b/tenacity/tests/test_tenacity.py
@@ -1107,6 +1107,25 @@ class TestBeforeAfterAttempts(unittest.TestCase):
             _test_before_sleep()
         self.assertEqual(_before_sleep.attempt_number, 2)
 
+    def _before_sleep(self, retry_state):
+        self.slept += 1
+
+    def test_before_sleep_backward_compat_method(self):
+        self.slept = 0
+
+        @retry(wait=tenacity.wait_fixed(0.01),
+               stop=tenacity.stop_after_attempt(3),
+               before_sleep=self._before_sleep)
+        def _test_before_sleep():
+            raise Exception("testing before_sleep_attempts handler")
+
+        try:
+            _test_before_sleep()
+        except tenacity.RetryError:
+            pass
+
+        self.assertEqual(self.slept, 2)
+
     def test_before_sleep_log_raises(self):
         thing = NoIOErrorAfterCount(2)
         logger = logging.getLogger(self.id())
Repository: jd/tenacity

Issue:
Asyncio: iscoroutinefunction does not work with tenacity
When decorating an `async` function with `@retry`, `asyncio.iscoroutinefunction(f)` unexpectedly returns `False`, because the wrapping function, in fact, is no coroutine.

This is a problem in some libraries that are using this way of determining if they are handling an async function or not (in my case: trafaret).

Comments:

Patch:
diff --git a/tenacity/_asyncio.py b/tenacity/_asyncio.py
index f93bf0f..035699d 100644
--- a/tenacity/_asyncio.py
+++ b/tenacity/_asyncio.py
@@ -38,6 +38,12 @@ if asyncio:
             super(AsyncRetrying, self).__init__(**kwargs)
             self.sleep = sleep
 
+        def wraps(self, fn):
+            fn = super().wraps(fn)
+            # Ensure wrapper is recognized as a coroutine function.
+            fn._is_coroutine = asyncio.coroutines._is_coroutine
+            return fn
+
         @asyncio.coroutine
         def call(self, fn, *args, **kwargs):
             self.begin(fn)


Test patch:
diff --git a/tenacity/tests/test_asyncio.py b/tenacity/tests/test_asyncio.py
index 6937511..8a8d3ce 100644
--- a/tenacity/tests/test_asyncio.py
+++ b/tenacity/tests/test_asyncio.py
@@ -36,9 +36,8 @@ def asynctest(callable_):
 
 
 @retry
-@asyncio.coroutine
-def _retryable_coroutine(thing):
-    yield from asyncio.sleep(0.00001)
+async def _retryable_coroutine(thing):
+    await asyncio.sleep(0.00001)
     return thing.go()
Repository: jdkandersson/OpenAlchemy

Issue:
Examine nullability of extension properties
Examine whether nullability of extension properties is a problem sine JSON schema does not support _nullable_.

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 311b4b60..baabd64f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
 
 - Add support for remote references to a file at a URL.
 - Add support for default values.
+- Add check for whether the value of an extension property is null.
 
 ## Version 0.14.0 - 2020-02-21
 
diff --git a/open_alchemy/helpers/get_ext_prop/__init__.py b/open_alchemy/helpers/get_ext_prop/__init__.py
index 3b694993..d254a3c3 100644
--- a/open_alchemy/helpers/get_ext_prop/__init__.py
+++ b/open_alchemy/helpers/get_ext_prop/__init__.py
@@ -45,9 +45,16 @@ def get_ext_prop(
         The value of the property or the default value if it does not exist.
 
     """
+    # Check for presence of name
+    if name not in source:
+        return default
+
+    # Retrieve value
     value = source.get(name)
     if value is None:
-        return default
+        raise exceptions.MalformedExtensionPropertyError(
+            f"The value of the {name} extension property cannot be null."
+        )
 
     schema = _SCHEMAS.get(name)
     try:


Test patch:
diff --git a/tests/open_alchemy/helpers/test_get_ext_prop.py b/tests/open_alchemy/helpers/test_get_ext_prop.py
index 6f78bf2d..c781c417 100644
--- a/tests/open_alchemy/helpers/test_get_ext_prop.py
+++ b/tests/open_alchemy/helpers/test_get_ext_prop.py
@@ -44,6 +44,7 @@ def test_miss_default():
         ("x-foreign-key", "no column"),
         ("x-foreign-key-column", True),
         ("x-tablename", True),
+        ("x-tablename", None),
         ("x-de-$ref", True),
         ("x-dict-ignore", "True"),
         ("x-generated", "True"),
@@ -60,6 +61,7 @@ def test_miss_default():
         "x-foreign-key invalid format",
         "x-foreign-key-column",
         "x-tablename",
+        "x-tablename None",
         "x-de-$ref",
         "x-dict-ignore",
         "x-generated",
diff --git a/tests/open_alchemy/test_model_factory.py b/tests/open_alchemy/test_model_factory.py
index f9031c15..a0ef659e 100644
--- a/tests/open_alchemy/test_model_factory.py
+++ b/tests/open_alchemy/test_model_factory.py
@@ -36,6 +36,27 @@ def test_missing_tablename():
         )
 
 
+@pytest.mark.model
+def test_tablename_none():
+    """
+    GIVEN schemas with schema that has None for the tablename
+    WHEN model_factory is called with the name of the schema
+    THEN MalformedExtensionPropertyError is raised.
+    """
+    with pytest.raises(exceptions.MalformedExtensionPropertyError):
+        model_factory.model_factory(
+            name="SingleProperty",
+            base=mock.MagicMock,
+            schemas={
+                "SingleProperty": {
+                    "x-tablename": None,
+                    "type": "object",
+                    "properties": {"property_1": {"type": "integer"}},
+                }
+            },
+        )
+
+
 @pytest.mark.model
 def test_not_object():
     """
Repository: jdkandersson/OpenAlchemy

Issue:
The typed dict cannot have types such as datetime
The typed dict of a models file should only have the basic OpenAPI types, it should not have python types such as `datetime` which currently is the case.

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dc8241c..adf69203 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 ## Version _next_
 
 - Add support for `readOnly`.
+- Fix bug where TypedDIct types for `binary`, `date` and `date-time` string formats mapped to the incorrect python types.
 
 ## Version 1.1.0 - 2020-04-05
 
diff --git a/open_alchemy/models_file/model/type_.py b/open_alchemy/models_file/model/type_.py
index 7bc55cd3..5b4b361d 100644
--- a/open_alchemy/models_file/model/type_.py
+++ b/open_alchemy/models_file/model/type_.py
@@ -72,6 +72,12 @@ def typed_dict(*, artifacts: types.ColumnSchemaArtifacts) -> str:
         model_type = model_type.replace(
             f"T{artifacts.de_ref}", f"{artifacts.de_ref}Dict"
         )
+    if artifacts.format == "binary":
+        model_type = model_type.replace("bytes", "str")
+    if artifacts.format == "date":
+        model_type = model_type.replace("datetime.date", "str")
+    if artifacts.format == "date-time":
+        model_type = model_type.replace("datetime.datetime", "str")
 
     return model_type
 


Test patch:
diff --git a/tests/open_alchemy/models_file/model/test_type.py b/tests/open_alchemy/models_file/model/test_type.py
index caa228af..1b2c0e13 100644
--- a/tests/open_alchemy/models_file/model/test_type.py
+++ b/tests/open_alchemy/models_file/model/test_type.py
@@ -106,23 +106,25 @@ def test_model(
 
 
 @pytest.mark.parametrize(
-    "type_, expected_type",
+    "type_, format_, expected_type",
     [
-        ("integer", "int"),
-        ("object", '"RefModelDict"'),
-        ("array", 'typing.Sequence["RefModelDict"]'),
+        pytest.param("integer", None, "typing.Optional[int]", id="plain"),
+        pytest.param("string", "binary", "typing.Optional[str]", id="binary"),
+        pytest.param("string", "date", "typing.Optional[str]", id="date"),
+        pytest.param("string", "date-time", "typing.Optional[str]", id="date-time"),
+        pytest.param("object", None, 'typing.Optional["RefModelDict"]', id="object"),
+        pytest.param("array", None, 'typing.Sequence["RefModelDict"]', id="array"),
     ],
-    ids=["plain", "object", "array"],
 )
 @pytest.mark.models_file
-def test_dict(type_, expected_type):
+def test_dict(type_, format_, expected_type):
     """
     GIVEN None format and required, False nullable and de_ref and given type
     WHEN typed_dict is called with the type, format, nullable, required and de_ref
     THEN the given expected type is returned.
     """
     artifacts = models_file.types.ColumnSchemaArtifacts(
-        type=type_, nullable=False, de_ref="RefModel"
+        type=type_, format=format_, nullable=True, de_ref="RefModel"
     )
 
     returned_type = models_file._model._type.typed_dict(artifacts=artifacts)
Repository: jdkandersson/OpenAlchemy

Issue:
Support byte
As a user I want to define a byte format so that I can store and retrieve base64 encoded values from the database.

Support byte as indicated by the appropriate format directive of a string.

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0e38c7e..e44f4266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
 ## Version _next_
 
+- Add support for _byte_
 - Add support for _date_
 - Move SQLAlchemy relationship construction behind facade
 - Move schema calculations into separate files
diff --git a/README.md b/README.md
index d92da4f9..4684c692 100644
--- a/README.md
+++ b/README.md
@@ -100,6 +100,7 @@ An example API has been defined using connexion and Flask here:
 - `number` (float only),
 - `boolean`,
 - `string`,
+- `byte`,
 - `date`,
 - `date-time`,
 - `$ref` references for columns and models,
diff --git a/docs/source/technical_details/type_mapping.rst b/docs/source/technical_details/type_mapping.rst
index 201d7faf..077313ac 100644
--- a/docs/source/technical_details/type_mapping.rst
+++ b/docs/source/technical_details/type_mapping.rst
@@ -19,6 +19,8 @@ following mappings:
 +--------------+----------------+-----------------+
 | string       | *undefined*    | String          |
 +--------------+----------------+-----------------+
+|              | byte           | String          |
++--------------+----------------+-----------------+
 |              | date           | Date            |
 +--------------+----------------+-----------------+
 |              | date-time      | DateTime        |
diff --git a/open_alchemy/column_factory/column.py b/open_alchemy/column_factory/column.py
index 76987e22..7a2874aa 100644
--- a/open_alchemy/column_factory/column.py
+++ b/open_alchemy/column_factory/column.py
@@ -272,7 +272,7 @@ def _handle_string(*, artifacts: types.ColumnArtifacts) -> sqlalchemy.String:
         raise exceptions.MalformedSchemaError(
             "The string type does not support autoincrement."
         )
-    if artifacts.format is None:
+    if artifacts.format in {None, "byte"}:
         if artifacts.max_length is None:
             return sqlalchemy.String
         return sqlalchemy.String(length=artifacts.max_length)


Test patch:
diff --git a/tests/open_alchemy/column_factory/test_column.py b/tests/open_alchemy/column_factory/test_column.py
index 96309c35..d2a11fe6 100644
--- a/tests/open_alchemy/column_factory/test_column.py
+++ b/tests/open_alchemy/column_factory/test_column.py
@@ -521,8 +521,9 @@ def test_handle_string_invalid_format():
         (None, sqlalchemy.String),
         ("date", sqlalchemy.Date),
         ("date-time", sqlalchemy.DateTime),
+        ("byte", sqlalchemy.String),
     ],
-    ids=["None", "date", "date-time"],
+    ids=["None", "date", "date-time", "byte"],
 )
 @pytest.mark.column
 def test_handle_string(format_, expected_type):