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)

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


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

It should be pylint issue. You can disable pylint warnings for a specific line by adding a comment "# pylint: disable=maybe-no-member" after the offending statement. see Hide some maybe-no-member Pylint errors

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


I understand that it makes sense to hide some errors by default but if a project explicitly configures the linter then I think the editor should not override local choices. I am specifically talking about cases where one of the following is true:.pylintrc exists; pylintrc exists; PYLINTRC environment variable is set and points to an existing file

Instead of



getattr(result, 'tobytes')()

If you specify a value in pylintArgs or use a Pylint configuration file (see the next section), then pylintUseMinimalCheckers is implicitly set to false. In other words, PyLint is supposedly pretty lax by default in VS Code, only showing you messages for errors and a few hand-picked warnings.

# pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code. You can use the message code or the symbolic names. For example. def test(): # Disable all the no-member violations in this function # pylint: disable=no-member global VAR # pylint: disable=global-statement

# pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code. 4.2 Is there a way to disable a message for a particular module only? Yes, you can disable or enable (globally disabled) messages at the module level by adding the corresponding option in a comment at the top of the file:

Steps to reproduce Install Visual Studio Code Install python support and install pylint Setup basic flask app Create Blueprint and import db from main init.py Current behavior severity: 'Error' message: 'E1101:Instance of 'SQLAlchemy' ha

  • In addition to <int>, what are the types that you expect to have ? (Str or bin .. )
  • array and int are enough
  • what if you check the type before. if isinstance(result, int) == False: read = result.tobytes()
  • @user3378649 No, but I like more "isinstance(result, array.array)", thanks
  • @user3378649 I still have the error, it is only that I like isinstance style more than the type compare. Don't you think that I would have insisted for a proper answer to reward you?
  • An additional explanatory note: adding the specified comment above the line disables the warning for the entire block (docs.pylint.org/…)
  • The link in the comment above is dead. This is the updated link.
  • Not only you disabled all E1101 warnings, good or bad, but you have to remember to add this parameter every time you use the command.
  • Well, it's in my VS Code config. You're not manually running your linting command every time you want to lint, right? You can add that option to a pylint rc file as well.
  • Config is better, but still disabling all. Yes, I do running my command every time since I am having mostly scripts and Python is either a hobby or an auxiliary testing tool at work (and they do not config :( ...)
  • I disabled the warning completely because I think if your linter is causing you to add anything to your code (comments to disable it), it's a shitty linter and I'd rather not have the warning than have false positives.. What are you using to edit your python programs? Unless it's Microsoft Word, you can probably configure the linter to run through the editor, every time you save and show the errors to you. Or you could install VS Code, the most popular code editor.
  • Trouble is the "no-member" check actually does catch a lot of fat finger code problems. So completely disabling it (while easy to do) will make my life a bit harder by letting the real problems through as well. With the latest pylint versions, I find false positives don't pop up that often. When they do, I just comment-disable them.
  • Changing code to be slower to make pylint happy is not in the spirit of the exercise. The goal is to be informed code can be made better. I come across this all the time and wish pylint would provide type hinting or use eeStructured text or other doc comment strategies to gain hints, but short of this feature, disabling is definitely the only solution (assuming the code is indeed clean already).