Ididi

Latest version: v1.4.2

Safety actively analyzes 703125 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 10

1.3.3

- `Graph.search_node`, search node by name, O(n) complexity

This is mainly for debugging purpose, sometimes you don't have access to the dependent type, but do know the name of it. example

python
class User: ...

dg = Graph()
dg.node(User)

assert dg.search_node("User").dependent_type is User


This is particularly useful for type defined by NewType

python
UserId = NewType("UserId", str)
assert dg.search_node("UserId")



- `Graph.override`

a helper function to override dependent within the graph

python
def override(self, old_dep: INode[P, T], new_dep: INode[P, T]) -> None:


python
dg = DependencyGraph()

dg.entry
async def create_user(
user_name: str, user_email: str, service: UserService
) -> UserService:
return service

dg.node
def user_factory() -> UserService:
return UserService("1", 2)

class FakeUserService(UserService): ...

dg.override(UserService, FakeUserService)

service_res = await create_user("1", "2")
assert isinstance(service_res, FakeUserService)


Note that, if you only want to override dependency for `create_user`
you can still just use `create_user.replace(UserService, FakeUserService)`,
and such override won't affect others.

1.3.2

- Now when override entry dependencies with `entryfunc.replace`, ididi will automatically analyze the override dependency

- `NodeConfig` is now immutable and hashable
- rename `Graph._analyze_entry` to `Graph.analyze_params`,

1.3.1

Features

Resolve NewType


py
from uuid import uuid4

UUID = NewType("UUID", str)


def uuid_factory() -> UUID:
return str(uuid4())

def user_factory(user_id: UUID) -> User:
return User(user_id=user_id)


Why not TypeAlias as well?

1. It does not make sense, since TypeAlias is literally an alias

A = str

means A is the same as str, and it make no sense to resolve a str.


2. Resolving TypeAlias is not possible in python 3.9

py
UUID = str

def uuid_factory() -> UUID:
return uuid4()

when we try to resolve uuid_factory, the return is a type `str`,
not a `TypeAlias`.

1.3.0

1.2.6

- override class dependencies, entry dependencies

py
class Repo:
db: DataBase = use(db_factory)


def fake_db_factory()->DataBase:
return FakeDB()

dg.node(fake_db_factory)


override entry

py
def test_entry_replace():
dg = DependencyGraph()

def create_user(
user_name: str, user_email: str, service: UserService
) -> UserService:
return service

class FakeUserService(UserService): ...

create_user = dg.entry(reuse=False)(create_user)
create_user.replace(UserService, FakeUserService)

res = create_user("user", "useremail.com")
assert isinstance(res, FakeUserService)


class EvenFaker(UserService):
...

create_user.replace(service=EvenFaker)
create_user.replace(UserService, service=EvenFaker)

res = create_user("user", "useremail.com")
assert isinstance(res, EvenFaker)

1.2.5

- remove `LazyDependent`, since `DependencyGraph` can inject itself to any dependencies it resolve,
`LazyDependent` can be easily achieved by injecting `DependencyGraph` and lazy resolve

py
from ididi import ignore

class UserRepo:
def __init__(self, graph: DependencyGraph, db: Ignore[DataBase]=None):
self._graph = graph
self._db = db

property
def db(self):
return self._graph.resolve(DataBase)



- performance boost

25% performance increase to `DependencyGraph.resolve` compare to 1.2.4

Current implementation of dg.resolve is 17.356008 times slower than a hard-coded dependency construction.
given how much extra work ididi does resolving dependency,
our ultimate goal would be make dg.resolve < 10 times slower than a hard-coded solution.

Page 2 of 10

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.