nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: reagento/dishka
Pull request #197 (2024-08-04 19:35:17)

Validate decorator really decorates


Patch:
diff --git a/src/dishka/dependency_source/make_decorator.py b/src/dishka/dependency_source/make_decorator.py
index ac0b613..6bf0be2 100644
--- a/src/dishka/dependency_source/make_decorator.py
+++ b/src/dishka/dependency_source/make_decorator.py
@@ -18,6 +18,16 @@ def _decorate(
         provides=provides, scope=None, source=source, cache=False,
         is_in_class=is_in_class,
     ))
+    if (
+        decorator.provides not in decorator.factory.kw_dependencies.values()
+        and decorator.provides not in decorator.factory.dependencies
+    ):
+        name = getattr(source, "__qualname__", "") or str(source)
+        raise ValueError(
+            f"Decorator {name} does not depends on provided type.\n"
+            f"Did you mean @provide instead of @decorate?",
+        )
+
     composite.dependency_sources.extend(unpack_decorator(decorator))
     return composite
 


Test patch:
diff --git a/tests/unit/test_provider.py b/tests/unit/test_provider.py
index 40bb617..7df39c5 100644
--- a/tests/unit/test_provider.py
+++ b/tests/unit/test_provider.py
@@ -3,7 +3,7 @@ from typing import Any, Protocol
 
 import pytest
 
-from dishka import Provider, Scope, alias, provide
+from dishka import Provider, Scope, alias, decorate, provide
 from dishka.dependency_source import FactoryType
 from dishka.dependency_source.make_factory import make_factory, provide_all
 from dishka.entities.key import (
@@ -214,12 +214,6 @@ def test_provide_as_method():
     assert factory.provides == hint_to_dependency_key(str)
     assert factory.source == hint_to_dependency_key(int)
 
-    foo = provider.decorate(sync_func_a)
-    assert len(foo.dependency_sources) == 1
-    factory = foo.dependency_sources[0]
-    assert factory.provides == hint_to_dependency_key(ClassA)
-    assert factory.factory.dependencies == hints_to_dependency_keys([Any, int])
-
 
 class OtherClass:
     def method(self) -> str:
@@ -290,3 +284,24 @@ def test_provide_join_provides_cls():
     assert len(provider.factories) == 2
     provides = [f.provides.type_hint for f in provider.factories]
     assert provides == [A, B]
+
+
+def test_decorator():
+    def sync_func_a(self: ClassA, dep: int) -> ClassA:
+        return ClassA(dep)
+
+    provider = Provider(scope=Scope.REQUEST)
+    foo = provider.decorate(sync_func_a)
+    assert len(foo.dependency_sources) == 1
+    factory = foo.dependency_sources[0]
+    assert factory.provides == hint_to_dependency_key(ClassA)
+    expected_deps = hints_to_dependency_keys([ClassA, int])
+    assert factory.factory.dependencies == expected_deps
+
+
+def test_invalid_decorator():
+    def decorator(param: int) -> str:
+        return "hello"
+
+    with pytest.raises(ValueError):  # noqa: PT011
+        decorate(decorator)
Repository: reagento/dishka
Pull request #205 (2024-08-10 19:36:19)

replace newtype with temporary object for decorators


Patch:
diff --git a/src/dishka/registry.py b/src/dishka/registry.py
index 440258d..84c9d2e 100644
--- a/src/dishka/registry.py
+++ b/src/dishka/registry.py
@@ -1,6 +1,6 @@
 from collections import defaultdict
 from collections.abc import Callable, Sequence
-from typing import Any, NewType, TypeVar, cast, get_args, get_origin
+from typing import Any, TypeVar, cast, get_args, get_origin
 
 from ._adaptix.type_tools.basic_utils import is_generic
 from ._adaptix.type_tools.fundamentals import get_type_vars
@@ -26,6 +26,16 @@ from .factory_compiler import compile_factory
 from .provider import BaseProvider
 
 
+class UndecoratedType:
+    """Container for a type which is decorated in other place."""
+    def __init__(self, original: type[Any], depth: int) -> None:
+        self.original = original
+        self.level = depth
+
+    def __repr__(self) -> str:
+        return f"UndecoratedType({self.original}, depth={self.level})"
+
+
 class Registry:
     __slots__ = ("scope", "factories", "compiled", "compiled_async")
 
@@ -320,9 +330,9 @@ class RegistryBuilder:
             )
         scope = self.dependency_scopes[provides]
         registry = self.registries[scope]
-        undecorated_type = NewType(  # type: ignore[misc]
-            f"{provides.type_hint.__name__}@{self.decorator_depth[provides]}",
-            decorator.provides.type_hint,  # type: ignore[name-defined]
+        undecorated_type = UndecoratedType(
+            decorator.provides.type_hint,
+            self.decorator_depth[provides],
         )
         self.decorator_depth[provides] += 1
         old_factory = registry.get_factory(provides)


Test patch:
diff --git a/tests/unit/container/test_decorator.py b/tests/unit/container/test_decorator.py
index b11cc7d..6a1f319 100644
--- a/tests/unit/container/test_decorator.py
+++ b/tests/unit/container/test_decorator.py
@@ -43,6 +43,23 @@ def test_simple():
     assert isinstance(a.a, A)
 
 
+def test_with_hint():
+    class MyProvider(Provider):
+        a = provide(A, scope=Scope.APP, provides=A|None)
+
+    class DProvider(Provider):
+        @decorate
+        def a(self, a: A|None) -> A|None:
+            if a is None:
+                return None
+            return ADecorator(a)
+
+    container = make_container(MyProvider(), DProvider())
+    a = container.get(A|None)
+    assert isinstance(a, ADecorator)
+    assert isinstance(a.a, A)
+
+
 def test_decorator():
     class MyProvider(Provider):
         a = provide(A, scope=Scope.APP)
Repository: reagento/dishka
Pull request #253 (2024-10-03 17:23:52)

Fix rendering NoFactoryError without path


Patch:
diff --git a/src/dishka/exceptions.py b/src/dishka/exceptions.py
index 23af56c..cdbb74a 100644
--- a/src/dishka/exceptions.py
+++ b/src/dishka/exceptions.py
@@ -77,7 +77,7 @@ class NoFactoryError(DishkaError):
             f"component={self.requested.component!r})"
         )
         suggestion = render_suggestions_for_missing(
-            requested_for=self.path[-1],
+            requested_for=self.path[-1] if self.path else None,
             requested_key=self.requested,
             suggest_other_scopes=self.suggest_other_scopes,
             suggest_other_components=self.suggest_other_components,
diff --git a/src/dishka/text_rendering/suggestion.py b/src/dishka/text_rendering/suggestion.py
index 6f2a736..0b82167 100644
--- a/src/dishka/text_rendering/suggestion.py
+++ b/src/dishka/text_rendering/suggestion.py
@@ -6,24 +6,28 @@ from .name import get_name
 
 
 def render_suggestions_for_missing(
-        requested_for: Factory,
+        requested_for: Factory | None,
         requested_key: DependencyKey,
         suggest_other_scopes: Sequence[Factory],
         suggest_other_components: Sequence[Factory],
 ):
     suggestion = ""
     if suggest_other_scopes:
-        src_name = get_name(requested_for.source, include_module=False)
         scopes = " or ".join(
             str(factory.scope)
             for factory in suggest_other_scopes
         )
-        suggestion += f"\n * Try changing scope of `{src_name}` to {scopes}."
+        if requested_for:
+            srcname = get_name(requested_for.source, include_module=False)
+            suggestion += f"\n * Try changing scope of `{srcname}` to {scopes}"
+        else:
+            suggestion += f"\n * Check if you forgot enter {scopes}"
+
     if suggest_other_components:
         dep_name = get_name(requested_key.type_hint, include_module=True)
         components_str = " or ".join(
             f"Annotated[{dep_name}, FromComponent({f.provides.component!r})]"
             for f in suggest_other_components
         )
-        suggestion += f"\n * Try using {components_str}."
+        suggestion += f"\n * Try using {components_str}"
     return suggestion


Test patch:
diff --git a/tests/unit/container/test_exceptions.py b/tests/unit/container/test_exceptions.py
index 56501c0..0fb277c 100644
--- a/tests/unit/container/test_exceptions.py
+++ b/tests/unit/container/test_exceptions.py
@@ -150,6 +150,7 @@ def test_no_factory_sync():
     with pytest.raises(NoFactoryError) as e:
         container.get(object)
     assert e.value.requested == DependencyKey(object, DEFAULT_COMPONENT)
+    assert str(e.value)
 
 
 def test_no_factory_path_sync():
@@ -157,6 +158,7 @@ def test_no_factory_path_sync():
     with pytest.raises(NoFactoryError) as e:
         container.get(complex)
     assert e.value.requested == DependencyKey(object, DEFAULT_COMPONENT)
+    assert str(e.value)
 
 
 @pytest.mark.asyncio
Repository: reagento/dishka
Pull request #274 (2024-10-16 20:20:03)

Fix ordering dependency sources and add decorator test


Patch:
diff --git a/src/dishka/dependency_source/composite.py b/src/dishka/dependency_source/composite.py
index 83ad004..b03093a 100644
--- a/src/dishka/dependency_source/composite.py
+++ b/src/dishka/dependency_source/composite.py
@@ -18,11 +18,15 @@ class CompositeDependencySource:
             self,
             origin: Any,
             dependency_sources: Sequence[DependencySource] = (),
+            number: int | None = None,
     ) -> None:
         self.dependency_sources = list(dependency_sources)
         self.origin = origin
-        self.number = self._instances
-        CompositeDependencySource._instances += 1
+        if number is None:
+            self.number = self._instances
+            CompositeDependencySource._instances += 1
+        else:
+            self.number = number
 
     def __get__(self, instance: Any, owner: Any) -> CompositeDependencySource:
         try:
@@ -34,6 +38,7 @@ class CompositeDependencySource:
             dependency_sources=[
                 s.__get__(instance, owner) for s in self.dependency_sources
             ],
+            number=self.number,
         )
 
     def __call__(self, *args: Any, **kwargs: Any) -> Any:


Test patch:
diff --git a/tests/unit/container/test_decorator.py b/tests/unit/container/test_decorator.py
index 0d7df2e..153f43e 100644
--- a/tests/unit/container/test_decorator.py
+++ b/tests/unit/container/test_decorator.py
@@ -213,6 +213,27 @@ def test_generic_decorator():
     assert a.a == 17
 
 
+def test_generic_double_decorator():
+    class MyProvider(Provider):
+        scope = Scope.APP
+
+        @provide(scope=Scope.APP)
+        def bar(self) -> int:
+            return 17
+
+        @decorate
+        def dec(self, a: int) -> int:
+            return a+1
+
+        @decorate
+        def baz(self, a: Tint) -> Tint:
+            return a*2
+
+    container = make_container(MyProvider())
+    a = container.get(int)
+    assert a == (17+1)*2
+
+
 def test_generic_decorator_generic_factory():
     class MyProvider(Provider):
         scope = Scope.APP
Repository: reagento/dishka
Pull request #345 (2025-01-17 22:53:17)

fix `provide_all`: wrong `provides=` value


Patch:
diff --git a/src/dishka/dependency_source/make_factory.py b/src/dishka/dependency_source/make_factory.py
index deb7280..c932929 100644
--- a/src/dishka/dependency_source/make_factory.py
+++ b/src/dishka/dependency_source/make_factory.py
@@ -627,7 +627,7 @@ def _provide_all(
     for single_provides in provides:
         source = _provide(
             source=single_provides,
-            provides=single_provides,
+            provides=None,
             scope=scope,
             cache=cache,
             is_in_class=is_in_class,


Test patch:
diff --git a/tests/unit/test_provider.py b/tests/unit/test_provider.py
index d49d351..eb8339c 100644
--- a/tests/unit/test_provider.py
+++ b/tests/unit/test_provider.py
@@ -3,7 +3,7 @@ from typing import Any, Protocol
 
 import pytest
 
-from dishka import Provider, Scope, alias, decorate, provide
+from dishka import Provider, Scope, alias, decorate, make_container, provide
 from dishka.dependency_source.make_factory import make_factory, provide_all
 from dishka.entities.factory_type import FactoryType
 from dishka.entities.key import (
@@ -306,3 +306,43 @@ def test_invalid_decorator():
 
     with pytest.raises(ValueError):  # noqa: PT011
         decorate(decorator)
+
+
+def test_provide_all_as_provider_method():
+    def a() -> int:
+        return 100
+
+    def b(num: int) -> float:
+        return num / 2
+
+    provider = Provider(scope=Scope.APP)
+    provider.provide_all(a, b)
+
+    container = make_container(provider)
+
+    hundred = container.get(int)
+    assert hundred == 100
+
+    fifty = container.get(float)
+    assert fifty == 50.0
+
+
+def test_provide_all_in_class():
+    class MyProvider(Provider):
+        scope = Scope.APP
+
+        def a(self) -> int:
+            return 100
+
+        def b(self, num: int) -> float:
+            return num / 2
+
+        abcd = provide_all(a, b)
+
+    container = make_container(MyProvider())
+
+    hundred = container.get(int)
+    assert hundred == 100
+
+    fifty = container.get(float)
+    assert fifty == 50.0
Repository: reagento/dishka
Pull request #408 (2025-03-23 08:23:52)

Validation in InjectedFuncType: raise error for async container in sync context
Validate `InjectedFuncType` and raise `InvalidInjectedFuncTypeError` for invalid async container usage
Added validation in `__post_init__` of `InjectedFuncType` to prevent using an async container in a synchronous context.
Added a test case using `pytest.raises` to ensure the error is correctly triggered.

It might be worth creating a package and splitting the `base` module, also include the `exceptions` file in that package. But this will not be necessary if the integrations are taken out of the library


Patch:
diff --git a/src/dishka/integrations/base.py b/src/dishka/integrations/base.py
index 5f1e363..31f35bd 100644
--- a/src/dishka/integrations/base.py
+++ b/src/dishka/integrations/base.py
@@ -35,6 +35,7 @@ from dishka.container import Container
 from dishka.entities.component import DEFAULT_COMPONENT
 from dishka.entities.depends_marker import FromDishka
 from dishka.entities.key import DependencyKey, _FromComponent
+from dishka.integrations.exceptions import InvalidInjectedFuncTypeError
 
 T = TypeVar("T")
 P = ParamSpec("P")
@@ -335,6 +336,13 @@ class InjectedFuncType:
     manage_scope: bool
     func_type: FunctionType
 
+    def __post_init__(self) -> None:
+        if self.is_async_container and self.func_type in (
+            FunctionType.GENERATOR,
+            FunctionType.CALLABLE,
+        ):
+            raise InvalidInjectedFuncTypeError
+
 
 _GET_AUTO_INJECTED_FUNC_DICT = {
     InjectedFuncType(
diff --git a/src/dishka/integrations/exceptions.py b/src/dishka/integrations/exceptions.py
new file mode 100644
index 0000000..f04a7a3
--- /dev/null
+++ b/src/dishka/integrations/exceptions.py
@@ -0,0 +1,9 @@
+from dishka.exception_base import DishkaError
+
+
+class InvalidInjectedFuncTypeError(DishkaError):
+    def __str__(self) -> str:
+        return (
+            "An async container cannot be used in a synchronous context."
+        )
+


Test patch:
diff --git a/tests/integrations/base/test_wrap_injection.py b/tests/integrations/base/test_wrap_injection.py
new file mode 100644
index 0000000..bdf9789
--- /dev/null
+++ b/tests/integrations/base/test_wrap_injection.py
@@ -0,0 +1,30 @@
+from collections.abc import Callable, Iterable, Iterator
+from unittest.mock import Mock
+
+import pytest
+
+from dishka import AsyncContainer, FromDishka
+from dishka.integrations.base import wrap_injection
+from dishka.integrations.exceptions import InvalidInjectedFuncTypeError
+
+
+def sync_func(mock: FromDishka[Mock]) -> None:
+    mock.some_func()
+
+
+def sync_gen(data: Iterable[int], x: FromDishka[Mock]) -> Iterator[int]:
+    for i in data:
+        yield x.some_func(i)
+
+
+@pytest.mark.parametrize("func", [sync_func, sync_gen])
+def test_invalid_injected_func_type(
+    func: Callable,
+    async_container: AsyncContainer,
+) -> None:
+    with pytest.raises(InvalidInjectedFuncTypeError):
+        wrap_injection(
+            func=func,
+            container_getter=lambda *_: async_container,
+            is_async=True,
+        )
Repository: rust-analyzer/rust-analyzer
Pull request #6713 (2020-12-03 18:08:01)

Make `compile_error!` message match upstream rustc
It only consists of the argument passed to it.

bors r+


Patch:
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 16c3c4d69c..44a5556b67 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -271,10 +271,7 @@ fn compile_error_expand(
             let text = it.text.as_str();
             if text.starts_with('"') && text.ends_with('"') {
                 // FIXME: does not handle raw strings
-                mbe::ExpandError::Other(format!(
-                    "`compile_error!` called: {}",
-                    &text[1..text.len() - 1]
-                ))
+                mbe::ExpandError::Other(text[1..text.len() - 1].to_string())
             } else {
                 mbe::ExpandError::BindingError("`compile_error!` argument must be a string".into())
             }


Test patch:
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index 7e78340ee4..6dba9817d4 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -107,7 +107,7 @@ fn f() {
   //^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "load out dirs from check" to fix
 
     compile_error!("compile_error works");
-  //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `compile_error!` called: compile_error works
+  //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ compile_error works
 
     // Lazy:
Repository: rust-analyzer/rust-analyzer
Pull request #6723 (2020-12-04 17:44:04)

Use correct, full substs for self type in impl
Without arbitrary self types, the self type could never refer to the method type parameters, so this wasn't a problem; but with arbitrary self types, it can.

This fixes the crash from #6668; but it doesn't make method resolution work for these methods.


Patch:
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 5a6f0c67fb..8a289f52a6 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -720,7 +720,13 @@ fn transform_receiver_ty(
             .push(self_ty.value.clone())
             .fill_with_unknown()
             .build(),
-        AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
+        AssocContainerId::ImplId(impl_id) => {
+            let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?;
+            Substs::build_for_def(db, function_id)
+                .use_parent_substs(&impl_substs)
+                .fill_with_unknown()
+                .build()
+        }
         AssocContainerId::ContainerId(_) => unreachable!(),
     };
     let sig = db.callable_item_signature(function_id.into());


Test patch:
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs
index 0f17ff1517..a6a54e542a 100644
--- a/crates/hir_ty/src/tests/method_resolution.rs
+++ b/crates/hir_ty/src/tests/method_resolution.rs
@@ -1087,3 +1087,22 @@ fn method_resolution_foreign_opaque_type() {
         "#]],
     );
 }
+
+#[test]
+fn method_with_allocator_box_self_type() {
+    check_types(
+        r#"
+struct Slice<T> {}
+struct Box<T, A> {}
+
+impl<T> Slice<T> {
+    pub fn into_vec<A>(self: Box<Self, A>) { }
+}
+
+fn main() {
+    let foo: Slice<u32>;
+    (foo.into_vec()); // we don't actually support arbitrary self types, but we shouldn't crash at least
+} //^ {unknown}
+"#,
+    );
+}
Repository: edgedb/edgedb-cli
Pull request #1486 (2025-02-20 21:33:26)

Fix Docker image builds
Broken in #1471



Patch:
diff --git a/.github/workflows.src/build.inc.yml b/.github/workflows.src/build.inc.yml
index e7153ef..20816a7 100644
--- a/.github/workflows.src/build.inc.yml
+++ b/.github/workflows.src/build.inc.yml
@@ -461,7 +461,7 @@
         FROM scratch
         COPY --from=download /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
         COPY --from=download /tmp/gel /usr/bin/gel
-        RUN ln -s gel /usr/bin/edgedb
+        COPY --from=download /tmp/gel /usr/bin/edgedb
         ENTRYPOINT ["/usr/bin/gel"]
         EOF
     - env:
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index a2b9225..27a8b47 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -2741,7 +2741,7 @@ jobs:
         FROM scratch
         COPY --from=download /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
         COPY --from=download /tmp/gel /usr/bin/gel
-        RUN ln -s gel /usr/bin/edgedb
+        COPY --from=download /tmp/gel /usr/bin/edgedb
         ENTRYPOINT ["/usr/bin/gel"]
         EOF
     - env:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 73cb29e..7ad380e 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -2230,7 +2230,7 @@ jobs:
         FROM scratch
         COPY --from=download /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
         COPY --from=download /tmp/gel /usr/bin/gel
-        RUN ln -s gel /usr/bin/edgedb
+        COPY --from=download /tmp/gel /usr/bin/edgedb
         ENTRYPOINT ["/usr/bin/gel"]
         EOF
     - env:


Test patch:
diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml
index 2220955..10bd08e 100644
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -2299,7 +2299,7 @@ jobs:
         FROM scratch
         COPY --from=download /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
         COPY --from=download /tmp/gel /usr/bin/gel
-        RUN ln -s gel /usr/bin/edgedb
+        COPY --from=download /tmp/gel /usr/bin/edgedb
         ENTRYPOINT ["/usr/bin/gel"]
         EOF
     - env: