Correct way to write type hints for keys and items

前端 未结 1 1700
天涯浪人
天涯浪人 2020-12-20 10:34

I have some Python code (running for Python 3.5, 3.6 and 3.7) and added some type hints for static type checks using mypy.

Please take a look at the following snippe

相关标签:
1条回答
  • 2020-12-20 11:06

    You can use typing module

    import typing
    
    class MyParams(Singleton, metaclass=MyParamsMeta):
        @classmethod
        def keys(cls) -> typing.collections.KeysView:
            return cls._params.keys()
    
        @classmethod
        def items(cls) -> typing.collections.ItemsView:
            return cls._params.items()
    
        _params = _load_from_csv()  # returns Dict[str, MyParam]
    
    0 讨论(0)
提交回复
热议问题