Skip to content

Instantly share code, notes, and snippets.

@podhmo
Last active February 13, 2020 13:05
Show Gist options
  • Save podhmo/66e1023a4c7a105add284f9f42cb0d88 to your computer and use it in GitHub Desktop.
Save podhmo/66e1023a4c7a105add284f9f42cb0d88 to your computer and use it in GitHub Desktop.
from monogusa import component
class Foo:
pass
@component
def foo() -> Foo:
return Foo()
def use(foo: Foo) -> None:
print(foo)
if __name__ == "__main__":
from monogusa.cli import run
run()
from monogusa import component
class Foo:
pass
@component
def foo() -> Foo:
return Foo()
def use(f: Foo) -> None:
print(f)
if __name__ == "__main__":
from monogusa.cli import run
run()
from monogusa import default_component
class Foo:
pass
@default_component
def foo() -> Foo:
return Foo()
def use(f: Foo) -> None:
print(f)
if __name__ == "__main__":
from monogusa.cli import run
run()
from monogusa import component
from monogusa.dependencies import resolve_args
@component
def one() -> int:
return 1
def use(one: int) -> None:
print(one)
print("!", resolve_args(use))
# ! [1]
import typing_extensions as tx
from monogusa import default_component
from monogusa.dependencies import resolve_args
@tx.runtime_checkable
class P(tx.Protocol):
def foo(self) -> str:
...
class I:
def foo(self) -> str:
return "I"
@default_component
def foo() -> P:
return I()
def use(p: P) -> None:
print(p.foo())
use(*resolve_args(use))
import abc
from monogusa import default_component
from monogusa.dependencies import resolve_args
class P(abc.ABC):
def foo(self) -> str:
...
class I(P):
def foo(self) -> str:
return "I"
@default_component
def foo() -> P:
return I()
def use(p: P) -> None:
print(p.foo())
use(*resolve_args(use))
00:
python $(shell echo $@*.py) use
01:
python $(shell echo $@*.py) use
02:
python $(shell echo $@*.py) use
03:
python $(shell echo $@*.py)
04:
python $(shell echo $@*.py)
05:
python $(shell echo $@*.py)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment