potiuk commented on a change in pull request #6749: [AIRFLOW-6193] Do not use asserts in Airflow main code URL: https://github.com/apache/airflow/pull/6749#discussion_r355171883
########## File path: tests/airflow_pylint/do_not_use_asserts.py ########## @@ -0,0 +1,43 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from pylint.checkers import BaseChecker +from pylint.interfaces import IAstroidChecker +from pylint.lint import PyLinter + + +class DoNotUseAssertsChecker(BaseChecker): + __implements__ = IAstroidChecker + + name = 'do-not-use-asserts' + priority = -1 + msgs = { + 'E7401': ( + 'Do not use asserts.', + 'do-not-use-asserts', + 'Asserts should not be used in the main Airflow code.' + ), + } + + def visit_assert(self, node): + self.add_message( + self.name, node=node, + ) Review comment: @kaxil visit_assert is only called when there is an actual assert in the code parsed by Pylint. Pylint uses astroid to read the AST of python code and it will call visit_<lowercase_token> for all tokens parsed. This means that visi_assert will only be called when assert instruction is used. I was inspired by @BasPH https://github.com/BasPH/pylint-airflow which uses pylint plugins to verify DAGs and implemented it for assert checking. BTW. I think we should add more and more of those pylint plugins which are airflow-specific. for example we should be able to write - fairly easily - a pylint plugin that would prevent o instantiate Hooks inside of the __init__ methods of the operators or to prevent calling a DB instruction (such as reading Airflow Variables). Implementing assert plugin is the first step (and we should finalize pylint introduction and get rid of pylint_todo.txt). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
