如何在 python3 中输入注释 tensorflow.Session()

How to type-annotate tensorflow.Session() in python3

我试图为 tf.Session() 的参数注释类型。

在命令行中,type(tf.Session())是这样的:

>>> type(tf.Session())
>>> <class 'tensorflow.python.client.session.Session'>

然后,我尝试着这样标注。

def func_with_sess_arg(image: np.ndarray,
                       sess: tf.python.client.session.Session):
                       ...

但是它提高了

Traceback (most recent call last):
File "func_with_sess_arg.py", line 13, in <module>
    sess: tf.python.client.session.Session):
AttributeError: 'module' object has no attribute 'python'

如何正确注释 tf.Session() 的参数类型?

只需输入

def func_with_sess_arg(image: np.ndarray,
                       sess: tf.Session):
                       ...