Repository: reagento/dishka

Issue:
Recursion in provide with source=random
MRO
```py
from random import random

from dishka import provide, Provider, Scope


class MyProvider(Provider):
    scope = Scope.APP
    rand = provide(source=random, provides=float)
```



Discussion:

Patch:
diff --git a/src/dishka/dependency_source/make_factory.py b/src/dishka/dependency_source/make_factory.py
index 91efb63..f9db170 100644
--- a/src/dishka/dependency_source/make_factory.py
+++ b/src/dishka/dependency_source/make_factory.py
@@ -10,6 +10,7 @@ from collections.abc import (
 )
 from inspect import (
     isasyncgenfunction,
+    isbuiltin,
     isclass,
     iscoroutinefunction,
     isfunction,
@@ -226,7 +227,7 @@ def _make_factory_by_class(
     )
 
 
-def _make_factory_by_method(
+def _make_factory_by_function(
         *,
         provides: Any,
         scope: BaseScope | None,
@@ -387,10 +388,15 @@ def make_factory(
             provides=provides, scope=scope, source=source, cache=cache,
         )
     elif isfunction(source) or isinstance(source, classmethod):
-        return _make_factory_by_method(
+        return _make_factory_by_function(
             provides=provides, scope=scope, source=source, cache=cache,
             is_in_class=is_in_class,
         )
+    elif isbuiltin(source):
+        return _make_factory_by_function(
+            provides=provides, scope=scope, source=source, cache=cache,
+            is_in_class=False,
+        )
     elif isinstance(source, staticmethod):
         return _make_factory_by_static_method(
             provides=provides, scope=scope, source=source, cache=cache,


Test patch:
diff --git a/tests/unit/test_provider.py b/tests/unit/test_provider.py
index f788642..acf7ecb 100644
--- a/tests/unit/test_provider.py
+++ b/tests/unit/test_provider.py
@@ -1,3 +1,4 @@
+from random import random
 from typing import Any, Protocol
 
 import pytest
@@ -273,3 +274,9 @@ def test_provide_all_instance():
     assert len(provider.factories) == 2
     provides = [f.provides.type_hint for f in provider.factories]
     assert provides == [A, B]
+
+
+def test_privde_random():
+    source = provide(source=random, provides=float)
+    assert len(source.dependency_sources) == 1
+    assert not source.dependency_sources[0].dependencies