From 605e95fc7939123f1b6b8d5b467fefd589636d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 1 Mar 2020 12:33:52 +0100 Subject: [PATCH] Fix flake8 errors and warnings We add the flake8 configuration used so we ensure everyone uses the same. We remove the usage of __all__ for non public API. When possible, we rationalize the class name according to its __name__ and module. issue9082 review297061002 --- .flake8 | 2 ++ __init__.py | 25 ++++++++++++++----------- account.py | 12 ++++-------- line.py | 2 -- rule.py | 2 -- setup.py | 7 ++++--- tests/__init__.py | 2 +- 7 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..bb03d08a82 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore=E123,E124,E126,E128,W503 diff --git a/__init__.py b/__init__.py index 0372f44c74..cb687dea8e 100644 --- a/__init__.py +++ b/__init__.py @@ -2,23 +2,26 @@ # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -from .account import * -from .line import * +from . import account +from . import line from . import rule +from .account import AnalyticMixin + +__all__ = [AnalyticMixin] def register(): Pool.register( - Account, - AccountDistribution, - OpenChartAccountStart, - AnalyticAccountEntry, - Line, - Move, - MoveLine, + account.Account, + account.AccountDistribution, + account.OpenChartAccountStart, + account.AnalyticAccountEntry, + line.Line, + line.Move, + line.MoveLine, rule.Rule, module='analytic_account', type_='model') Pool.register( - OpenChartAccount, - OpenAccount, + account.OpenChartAccount, + line.OpenAccount, module='analytic_account', type_='wizard') diff --git a/account.py b/account.py index 15e5dbd90a..7dbaf7d470 100644 --- a/account.py +++ b/account.py @@ -3,7 +3,7 @@ from decimal import Decimal from collections import defaultdict -from sql import Column +from sql import Column, Literal, Null from sql.aggregate import Sum from sql.conditionals import Coalesce @@ -18,10 +18,6 @@ from trytond.pool import Pool from .exceptions import AccountValidationError -__all__ = ['Account', 'AccountDistribution', - 'OpenChartAccountStart', 'OpenChartAccount', - 'AnalyticAccountEntry', 'AnalyticMixin'] - class Account( DeactivableMixin, tree('distribution_parents'), tree(), @@ -191,7 +187,7 @@ class Account( Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)), where=(table.type != 'view') & table.id.in_(all_ids) - & (table.active == True) & line_query, + & (table.active == Literal(True)) & line_query, group_by=table.id)) account_sum = defaultdict(Decimal) for account_id, value in cursor.fetchall(): @@ -245,7 +241,7 @@ class Account( ).select(*columns, where=(table.type != 'view') & table.id.in_(ids) - & (table.active == True) & line_query, + & (table.active == Literal(True)) & line_query, group_by=table.id)) for row in cursor.fetchall(): @@ -486,7 +482,7 @@ class AnalyticMixin(object): entry = AccountEntry.__table__() table = cls.__table__() cursor.execute(*table.select(table.id, table.analytic_accounts, - where=table.analytic_accounts != None)) + where=table.analytic_accounts != Null)) for line_id, selection_id in cursor.fetchall(): cursor.execute(*entry.update( columns=[entry.origin], diff --git a/line.py b/line.py index 8335dbbc8f..37ace8fbc8 100644 --- a/line.py +++ b/line.py @@ -11,8 +11,6 @@ from trytond.pyson import Eval, PYSONEncoder from trytond.transaction import Transaction from trytond.pool import Pool, PoolMeta -__all__ = ['Line', 'Move', 'MoveLine', 'OpenAccount'] - class Line(ModelSQL, ModelView): 'Analytic Line' diff --git a/rule.py b/rule.py index d1838d6aeb..e9d17aaa13 100644 --- a/rule.py +++ b/rule.py @@ -7,8 +7,6 @@ from trytond.transaction import Transaction from .account import AnalyticMixin -__all__ = ['Rule'] - class Rule(sequence_ordered(), MatchMixin, AnalyticMixin, ModelSQL, ModelView): "Analytic Rule" diff --git a/setup.py b/setup.py index d5d6b1bbe7..dfdad26901 100755 --- a/setup.py +++ b/setup.py @@ -79,8 +79,8 @@ setup(name=name, keywords='tryton analytic account', package_dir={'trytond.modules.analytic_account': '.'}, packages=( - ['trytond.modules.analytic_account'] + - ['trytond.modules.analytic_account.%s' % p for p in find_packages()] + ['trytond.modules.analytic_account'] + + ['trytond.modules.analytic_account.%s' % p for p in find_packages()] ), package_data={ 'trytond.modules.analytic_account': (info.get('xml', []) @@ -93,7 +93,8 @@ setup(name=name, 'Intended Audience :: Developers', 'Intended Audience :: Financial and Insurance Industry', 'Intended Audience :: Legal Industry', - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', + 'License :: OSI Approved :: ' + 'GNU General Public License v3 or later (GPLv3+)', 'Natural Language :: Bulgarian', 'Natural Language :: Catalan', 'Natural Language :: Chinese (Simplified)', diff --git a/tests/__init__.py b/tests/__init__.py index 678a810a71..8733763b2f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. try: - from trytond.modules.analytic_account.tests.test_analytic_account import suite + from trytond.modules.analytic_account.tests.test_analytic_account import suite # noqa: E501 except ImportError: from .test_analytic_account import suite