[Tutor] How to type annotate complex dictionary containing lambdas?

boB Stepp robertvstepp at gmail.com
Sun Nov 17 00:32:25 EST 2019


My best effort so far to type annotate the dictionary below is to use
"Any" for the dictionary values.  Is there a better substitute for
"Any" that would more precisely type annotate these dictionary values?

goal_year_params: Dict[str, Any] = {
          "greeting_msg": "Please enter the date by which you wish to attain"
          " your goal.\n",
          "input_prompt": "Enter year of your goal as an integer:  ",
          "date_value_err_ck": lambda goal_year: date(goal_year, 1, 1),
          "err_msg": "That is not a valid year.  Please try again.",
          "conditions": [
              (
                  lambda goal_year: goal_year < date.today().year,
                  lambda goal_year: print(
                      "Have you invented a time machine?  If not,
please enter a"
                      " year that makes more sense!"
                  ),
              ),
              (
                  lambda goal_year: goal_year >= date.today().year + 100,
                  lambda goal_year: print(
                      "Have you discovered the secret to eternal life?
 And how"
                      " long is this book anyway?  Please enter a year that"
                      " makes more sense."
                  ),
              ),
          ],
      }

-- 
boB


More information about the Tutor mailing list