Is it possible to create a regex-constrained type hint?

前端 未结 2 1769
再見小時候
再見小時候 2020-12-17 03:07

I have a helper function that converts a %Y-%m-%d %H:%M:%S-formatted string to a datetime.datetime:

def ymdt_to_datetime(ymdt: str)         


        
2条回答
  •  自闭症患者
    2020-12-17 03:37

    Using type-hints does nothing in Python and acts as an indication of the type in static checkers. It is not meant to perform any actions, merely annotate a type.

    You can't do any validation, all you can do, with type-hints and a checker, is make sure the argument passed in is actually of type str.

提交回复
热议问题