タグ

typingとformに関するishideoのブックマーク (1)

  • djangoのformが辛いという話 - podhmo's diary

    djangoのformが辛いという話 はじめに 例えば何らかの処理があるとする。それはある条件にマッチした場合にしか利用できない処理だとする。 T = TypeVar('T') class ActionDispatch(object): def test(self, x : T) -> str: return "A" or "B" or None def get_executor(self, kind : str) -> Callable[[T], None]: return on_a_action or on_b_action もちろん例なので実際には test() はBになり得るし、get_executor() 時にはon_b_actionが返ってくる場合もある。 これを使う処理をapi関数として切り出しておいてみる。以下の様な定義になると思う。 def get_executor(x

    djangoのformが辛いという話 - podhmo's diary
  • 1