renaming
- rename `DependencyGraph` to `Graph`
- rename `DependencyGraph.static_resolve` to `Graph.analyze`
- rename `DependencyGraph.static_resolve_all` to `Graph.analyze_nodes`
Original names are kept as alias to new names to avoid breaking changes
typing support
- support Unpack
py
class DataBase: ...
class Cache: ...
class Config: ...
class KWARGS(TypedDict):
db: DataBase
cache: Cache
class Extra(KWARGS):
config: Config
class Repo:
def __init__(self, **kwargs: Unpack[KWARGS]) -> None:
self.db = kwargs["db"]
self.cache = kwargs["cache"]
class SubRepo(Repo):
def __init__(self, **kwargs: Unpack[Extra]):
super().__init__(db=kwargs["db"], cache=kwargs["cache"])
self.config = kwargs["config"]
def test_resolve_unpack():
dg = Graph()
repo = dg.resolve(Repo)
assert isinstance(repo.db, DataBase)
assert isinstance(repo.cache, Cache)
subrepo = dg.resolve(SubRepo)
assert isinstance(subrepo.config, Config)
- support Literal
py
def test_resolve_literal():
dg = Graph()
class User:
def __init__(self, name: Literal["user"] = "user"):
self.name = name
u = dg.resolve(User)
assert u.name == "user"
Features
py
Graph.remove_singleton(self, dependent_type: type) -> None:
"Remove the registered singleton from current graph, return if not found"
Graph.remove_dependent(self, dependent_type: type) -> None
"Remove the dependent from current graph, return if not found"