Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to ignore specific error in pyre-check python package for the whole project

I am using pyre-checking for static type testing, I want to ignore specific error from my project.

For example: Undefined attribute [16]: Module google.protobuf.struct_pb2 has no attribute _STRUCT.

Suppose if I want to ignore this error from my project how can I do it?

like image 520
chethankumar MV Avatar asked Apr 16 '19 12:04

chethankumar MV


2 Answers

Another option is to fix this error rather than suppressing it.

Such errors happen when you use classes or attributes, or functions that exist in the .py file but are not defined in the appropriate .pyi file. In other words, such errors happen on inconsistencies between the source code and the type hint stub. In your case, the _STRUCT class was defined in the struct_pb2.py, but was not defined in the .pyi file supplied by Pyre developers, i.e., /pyre_check/typeshed/third_party/2and3/google/protobuf/struct_pb2.pyi.

In such cases, you may try to obtain the .pyi files from the developers of the appropriate package and replace the files in the pyre typeshed directory. However, the .pyi files provided by the developers of packages usually do not annotate classes or methods that start with _. According to PEP 8 -- Style Guide for Python Code | Python.org a name beginning with a single underscore is reserved for internal use

_single_leading_underscore: weak "internal use" indicator. E.g., from M import * does not import objects whose names start with an underscore.

Modules that are designed for use via from M import * should use the all mechanism to prevent exporting globals, or use the older convention of prefixing such globals with an underscore (which you might want to do to indicate these globals are "module non-public").

Use one leading underscore only for non-public methods and instance variables.

Public attributes should have no leading underscores.

internal interfaces (packages, modules, classes, functions, attributes or other names) should still be prefixed with a single leading underscore.

If you cannot get the update .pyi file from the developers, or it does not contain definitions for names prefixed with an underscore, you may add these names yourself to the .pyi file supplied by Pyre developers.

There also a small hint at Errors | Pyre (pyre-check.org)

like image 124
Maxim Masiutin Avatar answered Oct 06 '22 13:10

Maxim Masiutin


I am not familiar with your project but you have more options. I guess you can select the proper one for you.

You can suppress a specific error in your code with the following commented-out line:

# pyre-ignore[16]:
That part which raises the error

or

That part which raises the error  # pyre-ignore[16]

You can suppress all errors in your file if you declare the following commented-out line at beginning of your Python file:

# pyre-ignore-all-errors

You can exclude the problematic file or files with a regex (It is not totally recommended because the other errors also will be suppressed).

You can do it 2 ways:

  1. Put the exclude parameter to your PyRe config file (.pyre_configuration)
  2. Use the exclude argument in command line (--exclude EXCLUDE Exclude files and directories matching this regexp from parsing)

Honestly, I think your want to disable completely the Undefined attribute [16] error in your analysis but unfortunately currently this option is not supported by PyRe. Perhaps if you rewrite some parts of PyRe implementation, you can reach it but it is not nice and I guess it is not an option.

Referencies:

  • Error-supression

  • Configuration

like image 43
milanbalazs Avatar answered Oct 06 '22 13:10

milanbalazs