Allow lint to process and/or ignore non-valid python statements

Viewed 46

I have a set of Python scripts running in a vendor's SaaS environment that limits some of the features of Python (due to how they're running our scripts under the covers, in some kind of custom interactive environment).

For example, generators and lambdas are not valid.

There is also a non-Pythonic include statement with the syntax @include "Filename" that is preprocessed by the vendor like a C-include, where it just copy-pastes the referenced Python file into the referencing script.

I'd like to be able to lint my code and have it both:

  • understand and ignore the @include statements
  • understand how to modify Pylint's behavior to catch generators and lambdas
  • (optionally) understand system-specific global variables that are outside of the scope of the file being linted but always available at runtime in the SaaS

Is there any way to do this by modifying Pylint?

Bonus points if your solution does not modify the files you're linting (ie. un/comment out the @include).

1 Answers

It looks like you created a language of your own on top of python.

Parsing it is not possible currently in pylint. The only thing you could do is catch lambdas with "bad builtin" once you remove the @include (once it's python again). You could also create a custom checker to forbid generator. Everything else look like months of work on astroid (the AST used by pylint) and a whole project by itself.

Related