Question

Right now, if I have some function like this and I'd like to be able to get the error about index not being defined, while ignoring the error that some_index is not defined.

def myfunction(ind, other):
   """
   Parameters
   ----------
   ind: Index
   other: Index or set

   Returns
   -------
   Index.

   Examples
   --------

   >>> myfunction(some_index, other)
   """
   return index + other

If I run this through flake8 I get:

file.py:15:1: F821 undefined name 'other'
file.py:15:1: F821 undefined name 'some_index'
file.py:17:1: F821 undefined name 'index'

But what I want to see is just the index error and ignore the others:

file.py:17:1: F821 undefined name 'index'

If I run pylint or pyflakes on it, gives an error about some_index and other not being defined (which is True, but not necessarily useful all the time). How do I tell the programs to skip those errors? I'm working on a big library with many examples scattered throughout, some of which aren't defined but are just set to be examples of how to call them. Yes, it isn't great to not be able to run the doctests, but for the moment, it adds a ton of noise to pylint or pyflakes output. Flake8 doesn't seem to offer the option to skip them either.

How can I make this work? Is there an easy way to detect which things are docstrings in Python and filter the results that way?

Was it helpful?

Solution

Checking docstrings is a regression in pyflakes; please go comment on that bug to add your voice to the discussion.

You can disable it for now by setting the environment variable PYFLAKES_NODOCTEST.

OTHER TIPS

flake8 provides an option ignore:

flake8 --ignore=F821 a.py
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top