Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mypy是否有任何方法支持从函数中进行实例检查?_Python_Typing_Mypy_Static Typing_Isinstance - Fatal编程技术网

Python mypy是否有任何方法支持从函数中进行实例检查?

Python mypy是否有任何方法支持从函数中进行实例检查?,python,typing,mypy,static-typing,isinstance,Python,Typing,Mypy,Static Typing,Isinstance,mypy是否有任何方法支持从函数内部进行实例检查 我知道,isinstance对的支持。为了便于说明,我将以下模块作为最小示例: from typing import Any, Union def is_str(argument: Any) -> bool: return True if isinstance(argument, str) else False def my_string_function(input_str: str): print(input_str

mypy
是否有任何方法支持从函数内部进行实例检查

我知道,
isinstance
对的支持。为了便于说明,我将以下模块作为最小示例:

from typing import Any, Union

def is_str(argument: Any) -> bool:
    return True if isinstance(argument, str) else False

def my_string_function(input_str: str):
    print(input_str)

def my_string_and_int_function(argument: Union[str, int]):

    if is_str(argument):
        my_string_function(argument)

    if isinstance(argument, str):
        my_string_function(argument)
现在,如果我运行mypy,我会在
my\u string\u和my\u string\u函数
的第一个(不是第二个!)函数调用得到以下错误:

错误:“my_string_函数”的参数1具有不兼容的类型“Union[str,int]”;预期的“str”


也许这更适合mypy问题跟踪程序,但由于我不确定,我想先在这里发布。

目前还没有。不过这已经在路线图上了。谢谢你的信息!此功能将大大提高可用性!