Liviu
Liviu

Reputation: 1917

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)

Upvotes: 35

Views: 43438

Answers (4)

HadyKh
HadyKh

Reputation: 83

While using PyLint you can generate a configuration pylint file using these command in your terminal

$ pylint --generate-rcfile > .pylintrc

the generated file handles the errors and warnings that you have to check. for the no member in particular you can go to line 560, you can find that it ignored. this configurations will be applied to all your code files. and you can edit this configuration file, to meet your requirements.

Upvotes: 1

user3064538
user3064538

Reputation:

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

--disable=E1101

Upvotes: 2

sthenault
sthenault

Reputation: 15125

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()

Upvotes: 65

Brian
Brian

Reputation: 36

Instead of

result.tobytes(), 

use

getattr(result, 'tobytes')()

Upvotes: -8

Related Questions