mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 02:53:56 +03:00
daca85d555
* Fix a statement about coupling and cohesion that is not always true https://enterprisecraftsmanship.com/posts/cohesion-coupling-difference/#_types_of_code_from_a_cohesion_and_coupling_perspective * Fix a typing issue in an example `ApiClient` expects timeout to be an integer (based on a type hint), but `os.getenv` returns a string when `TIMEOUT` is set. * Specify the `None` return type where it is missed * Fix typing issues in some other places * Edit a statement about coupling and cohesion Co-authored-by: Roman Mogylatov <rmogilatov@gmail.com> Co-authored-by: Roman Mogylatov <rmogilatov@gmail.com>
30 lines
655 B
Python
30 lines
655 B
Python
import os
|
|
|
|
|
|
class ApiClient:
|
|
|
|
def __init__(self, api_key: str, timeout: int) -> None:
|
|
self.api_key = api_key # <-- dependency is injected
|
|
self.timeout = timeout # <-- dependency is injected
|
|
|
|
|
|
class Service:
|
|
|
|
def __init__(self, api_client: ApiClient) -> None:
|
|
self.api_client = api_client # <-- dependency is injected
|
|
|
|
|
|
def main(service: Service) -> None: # <-- dependency is injected
|
|
...
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(
|
|
service=Service(
|
|
api_client=ApiClient(
|
|
api_key=os.getenv("API_KEY"),
|
|
timeout=int(os.getenv("TIMEOUT")),
|
|
),
|
|
),
|
|
)
|