Pytorch study notes (nine) - some solutions for pycharm's automatic code completion

We know that python is a dynamic language. If the type of the return value cannot be known, pycharm will not be able to recognize the type of the return value, so code completion will not be possible. The following is how to solve this problem.

question

Code cannot be completed
insert image description here

Solution

1. For a single return value

Add as follows

""":type:返回值类型"""

Example:
insert image description here
or
add as follows

#type:返回值类型

example:
insert image description here

Second, for multiple return values

assert isinstance(返回的对象, 对象类型)

insert image description here
Or
select the object to be typed and press alt+enter to display a window, select Add type hint for variable 'xxx'.
insert image description here
The following code appears,
insert image description here
just change the object to a certain type
insert image description here

Guess you like

Origin blog.csdn.net/qq_23345187/article/details/122018551