Enter the pyi file when Pycharm views the function source code

        This tutorial is mainly to solve a common problem when using Pycharm. Although this problem will not have a great impact on writing code, it is a rather annoying thing for me personally.

Problem Description

        The problem is that when I am using Pycharm, I encounter an unfamiliar function and want to view the comments in the source code. I use the Pycharm shortcut key Ctrl + B or press and hold Ctrl to click on the corresponding function. It can jump normally, but it does not. Go to the normal source code, but jump to a .pyi file. In the .pyi file, there are only function calls without corresponding detailed comments.

        .pyi files are type hint files that are used to supplement type annotations in your code. These files are commonly used in type checking and static analysis tools such as MyPy. The .pyi file usually only contains the signature information of functions, classes, and methods, without the actual code implementation.

image-20230506165044888

         There are only function calling rules in the .pyi file, and comments and source code cannot be seen.

image-20230506165149457

 Online Error Tutorial Example

        All the tutorials on the Internet ask us to delete the .pyi file stub in the settings.image-20230506170726171

         After the deletion, there will be many new problems. For example, Pycharm cannot find the function during precompilation, resulting in a precompilation error (drawing a red wavy line); when viewing the function source code, multiple functions with the same name will be located (maybe in other libraries A function with the same name exists in ).

image-20230506171321361

image-20230506171336884         At this time, it is very difficult to find the source code of the function.

correct solution

        Also go to Settings, find file types, and click Ignored files and folders.

        Add *.pyi files here.

image-20230506171723973

 At this time, use the shortcut key to view the source code again to view the real source code.image-20230506171806467

Guess you like

Origin blog.csdn.net/liuqinhou/article/details/132125425