Search code examples
pythonpylint

robust pylint disable for an option recently introduced


We have several versions of pylint in various stages of our CI system (for good reasons: we want to test that our code works across a range of package versions).

Now, an option import-outside-toplevel was introduced as per pylint=2.4.0 (according to the changelog).

How do we disable that pylint error in a robust way (or conditional on pylint>=2.4.0)?

I have tried:

  1. # pylint: disable=import-outside-toplevel
  2. # pylint: disable=C0415
  3. No disable.

In case 1 and 2, running pylint version 2.4.3 (on a CI stage aligned with anaconda=2019.03) causes E0012: Bad option value. In case 3, running pylint version 2.4.2 (on a CI stage aligned with anaconda=2019.10) causes C0415: Import outside toplevel.


Solution

  • For now, I am disabling the whole 'C' category for just the scope (in my case, a single line):

    def blah(...):
        import foo.bar  # pylint: disable=C
    

    That works across pylint 2.3 to 2.5, although it isn't as specific as I would like.