Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support optional types injection #47

Merged
merged 5 commits into from
Sep 25, 2023
Merged

Support optional types injection #47

merged 5 commits into from
Sep 25, 2023

Conversation

dkraczkowski
Copy link
Contributor

@dkraczkowski dkraczkowski commented Sep 25, 2023

This PR adds support for optional types injection:

from kink import inject, di
from typing import Optional


class Message:
      def __init__(self, value: str) -> None:
          self.value = value

  di[Message] = Message("Hello world")

  @inject()
  def inject_test(a_message: Optional[Message] = None):
      if a_message:
          return a_message.value
      return ""

  assert inject_test() == "Hello world"

@dkraczkowski dkraczkowski merged commit 053b64e into master Sep 25, 2023
3 of 4 checks passed
@dkraczkowski dkraczkowski deleted the support-optionals branch September 25, 2023 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant