Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide some maybe-no-member Pylint errors

The following Python fragment code gets analyzed by Pylint:

if type(result) is array.array:
    read = result.tobytes()

... with the following error for the last line:

E:401,22: Instance of 'int' has no 'tobytes' member\ 
 (but some types could not be inferred) (maybe-no-member)

The result variable is received from an external function. How can I change (correct) the code to make Pylint understand? Or how can I tell it that the result of the function can have other types than int? Or how can I tell it to ignore that particular line? (I favor an answer in this order of the questions)

like image 1000
Liviu Avatar asked Oct 30 '14 15:10

Liviu


People also ask

Does Pylint have no member?

If you are getting the dreaded no-member error, there is a possibility that either: pylint found a bug in your code. You're launching pylint without the dependencies installed in its environment. pylint would need to lint a C extension module and is refraining to do so.

How do I know if a Pylint is ignoring a file?

The solution was to include --disable=file-ignored in the Pylint command options.


2 Answers

For some reason, pylint doesn't get 'result' may be of the array type (and will be for sure under the 'if' branch). There is currently no way to tell pylint about that, though it will hopefully be possible at some point. So for now, you can only disable the warning for that specific line by adding # pylint: disable=maybe-no-member after the offending statement or right above it. For example:

if type(result) is array.array:
    read = result.tobytes() # pylint: disable=maybe-no-member

or

if type(result) is array.array:
    # pylint: disable=maybe-no-member
    read = result.tobytes()
like image 91
sthenault Avatar answered Oct 21 '22 02:10

sthenault


I disabled all no-member warnings by passing this command line option to pylint

--disable=E1101
like image 25
Boris Avatar answered Oct 21 '22 01:10

Boris