Repository: reagento/dishka

Issue:
Generic decorator with multiple args is broken
```python
class A:
    pass


class A1(A):
    pass


class A2(A):
    pass


TA = TypeVar("TA", bound=A)


class P(Provider):
    scope = Scope.APP

    @provide
    def alist(self) -> list[A]:
        return []

    @decorate
    def adda(self, x: TA, many: list[A]) -> TA:
        many.append(x)
        return x

    a = provide_all(A1, A2)


c = make_container(P())
```

error
```
Traceback (most recent call last):
  File "/home/tishka17/src/dishka/tmp/collect_list.py", line 30, in <module>
    c = make_container(P())
        ^^^^^^^^^^^^^^^^^^^
  File "/home/tishka17/src/dishka/src/dishka/container.py", line 272, in make_container
    ).build()
      ^^^^^^^
  File "/home/tishka17/src/dishka/src/dishka/registry_builder.py", line 455, in build
    self._process_generic_decorator(provider, decorator)
  File "/home/tishka17/src/dishka/src/dishka/registry_builder.py", line 302, in _process_generic_decorator
    self._decorate_factory(
  File "/home/tishka17/src/dishka/src/dishka/registry_builder.py", line 387, in _decorate_factory
    new_factory = decorator.as_factory(
                  ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tishka17/src/dishka/src/dishka/dependency_source/decorator.py", line 52, in as_factory
    self._replace_dep(
  File "/home/tishka17/src/dishka/src/dishka/dependency_source/decorator.py", line 82, in _replace_dep
    old_key.type_hint[args],
    ~~~~~~~~~~~~~~~~~^^^^^^
TypeError: list[__main__.A] is not a generic class

```

Discussion:

Fix (patch):
diff --git a/src/dishka/dependency_source/decorator.py b/src/dishka/dependency_source/decorator.py
index bb30df4..92edc56 100644
--- a/src/dishka/dependency_source/decorator.py
+++ b/src/dishka/dependency_source/decorator.py
@@ -77,7 +77,10 @@ class Decorator:
             args = tuple(
                 typevar_replacement.get(t, t)
                 for t in get_args(old_key.type_hint)
+                if isinstance(t, TypeVar)
             )
+            if not args:
+                return old_key
             return DependencyKey(
                 old_key.type_hint[args],
                 self.provides.component,


Test changes:
diff --git a/tests/unit/container/test_decorator.py b/tests/unit/container/test_decorator.py
index d2e7c29..73cdb5b 100644
--- a/tests/unit/container/test_decorator.py
+++ b/tests/unit/container/test_decorator.py
@@ -253,6 +253,33 @@ def test_generic_decorator_generic_factory():
     assert a.a.value == ""
 
 
+
+class GenericTwoArgs(Generic[T]):
+    def __init__(self, value: object, others: object) -> None:
+        self.value = value
+        self.others = others
+
+
+def test_generic_multiple_args():
+    # https://github.com/reagento/dishka/issues/498
+    # one of the args in generic decorator can be concrete generic
+    class MyProvider(Provider):
+        scope = Scope.APP
+        value = provide(lambda self: 42, provides=int)
+        others = provide(lambda self: [17], provides=list[int])
+
+        @decorate
+        def dec(self, value: Tint, others: list[int]) -> Tint:
+            return GenericTwoArgs(value, others)
+
+    container = make_container(MyProvider())
+    # we expect double decoration here
+    a = container.get(int)
+    assert isinstance(a, GenericTwoArgs)
+    assert a.value == 42
+    assert a.others == [17]
+
+
 def test_decorate_alias():
 
     class MyProvider(Provider):