如何在python3中键入annotate tensorflow.Session()

如何在python3中键入annotate tensorflow.Session()

问题描述:

我试着注释tf.Session()参数的类型。如何在python3中键入annotate tensorflow.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): 
         ...