From f0eb9d3b6fd23f333510cc6ca55c6af62467b851 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Wed, 15 Sep 2021 14:51:56 +0200 Subject: [PATCH] There is no 'too complex function' We check a function's cognitive complexity only with `mccabe` (=C901) and not with WPS231 as the two overlap in most cases. --- noxfile.py | 4 ++-- setup.cfg | 3 +++ src/urban_meal_delivery/console/forecasts.py | 2 +- src/urban_meal_delivery/db/cities.py | 2 +- src/urban_meal_delivery/db/customers.py | 2 +- src/urban_meal_delivery/db/pixels.py | 2 +- src/urban_meal_delivery/db/restaurants.py | 2 +- src/urban_meal_delivery/forecasts/methods/decomposition.py | 2 +- tests/db/fake_data/factories/orders/ad_hoc.py | 4 +--- tests/db/test_orders.py | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/noxfile.py b/noxfile.py index f79025c..05106a6 100644 --- a/noxfile.py +++ b/noxfile.py @@ -384,7 +384,7 @@ def test_suite(session): @nox.session(name='fix-branch-references', python=PYTHON, venv_backend='none') -def fix_branch_references(session): # noqa:WPS210,WPS231 +def fix_branch_references(session): # noqa:WPS210 """Replace branch references with the current branch. Intended to be run as a pre-commit hook. @@ -511,7 +511,7 @@ def init_project(session): @nox.session(name='clean-pwd', python=PYTHON, venv_backend='none') -def clean_pwd(session): # noqa:WPS231 +def clean_pwd(session): """Remove (almost) all glob patterns listed in .gitignore. The difference compared to `git clean -X` is that this task diff --git a/setup.cfg b/setup.cfg index 070e376..df965ca 100644 --- a/setup.cfg +++ b/setup.cfg @@ -97,6 +97,9 @@ extend-ignore = WPS220, # String constant over-use is checked visually by the programmer. WPS226, + # Function complexity is checked by `mccabe` (=C901), + # which yields the same result in most cases. + WPS231, # Modules as a whole are assumed to be not "too complex". WPS232, # Allow underscores in numbers. diff --git a/src/urban_meal_delivery/console/forecasts.py b/src/urban_meal_delivery/console/forecasts.py index 5d2a20d..c91a7fd 100644 --- a/src/urban_meal_delivery/console/forecasts.py +++ b/src/urban_meal_delivery/console/forecasts.py @@ -24,7 +24,7 @@ from urban_meal_delivery.forecasts import timify @click.argument('time_step', default=60, type=int) @click.argument('train_horizon', default=8, type=int) @decorators.db_revision('8bfb928a31f8') -def tactical_heuristic( # noqa:C901,WPS213,WPS216,WPS231 +def tactical_heuristic( # noqa:C901,WPS213,WPS216 city: str, side_length: int, time_step: int, train_horizon: int, ) -> None: # pragma: no cover """Predict demand for all pixels and days in a city. diff --git a/src/urban_meal_delivery/db/cities.py b/src/urban_meal_delivery/db/cities.py index f00743f..e646046 100644 --- a/src/urban_meal_delivery/db/cities.py +++ b/src/urban_meal_delivery/db/cities.py @@ -117,7 +117,7 @@ class City(meta.Base): return self._map - def draw_restaurants( # noqa:WPS231 + def draw_restaurants( self, order_counts: bool = False, # pragma: no cover ) -> folium.Map: """Draw all restaurants on the`.map`. diff --git a/src/urban_meal_delivery/db/customers.py b/src/urban_meal_delivery/db/customers.py index 96106d1..384c003 100644 --- a/src/urban_meal_delivery/db/customers.py +++ b/src/urban_meal_delivery/db/customers.py @@ -42,7 +42,7 @@ class Customer(meta.Base): """Shortcut to the `...city.map` object.""" return self.orders[0].pickup_address.city.map # noqa:WPS219 - def draw( # noqa:C901,WPS210,WPS231 + def draw( # noqa:C901,WPS210 self, restaurants: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: """Draw all the customer's delivery addresses on the `...city.map`. diff --git a/src/urban_meal_delivery/db/pixels.py b/src/urban_meal_delivery/db/pixels.py index f7eb257..327e21d 100644 --- a/src/urban_meal_delivery/db/pixels.py +++ b/src/urban_meal_delivery/db/pixels.py @@ -136,7 +136,7 @@ class Pixel(meta.Base): """Shortcut to the `.city.map` object.""" return self.grid.city.map - def draw( # noqa:C901,WPS210,WPS231 + def draw( # noqa:C901,WPS210 self, restaurants: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: """Draw the pixel on the `.grid.city.map`. diff --git a/src/urban_meal_delivery/db/restaurants.py b/src/urban_meal_delivery/db/restaurants.py index 5a95ae1..fd838ab 100644 --- a/src/urban_meal_delivery/db/restaurants.py +++ b/src/urban_meal_delivery/db/restaurants.py @@ -69,7 +69,7 @@ class Restaurant(meta.Base): """Shortcut to the `.address.city.map` object.""" return self.address.city.map - def draw( # noqa:WPS231 + def draw( self, customers: bool = True, order_counts: bool = False, # pragma: no cover ) -> folium.Map: """Draw the restaurant on the `.address.city.map`. diff --git a/src/urban_meal_delivery/forecasts/methods/decomposition.py b/src/urban_meal_delivery/forecasts/methods/decomposition.py index c71f6be..3a96ac9 100644 --- a/src/urban_meal_delivery/forecasts/methods/decomposition.py +++ b/src/urban_meal_delivery/forecasts/methods/decomposition.py @@ -11,7 +11,7 @@ from rpy2 import robjects from rpy2.robjects import pandas2ri -def stl( # noqa:C901,WPS210,WPS211,WPS231 +def stl( # noqa:C901,WPS210,WPS211 time_series: pd.Series, *, frequency: int, diff --git a/tests/db/fake_data/factories/orders/ad_hoc.py b/tests/db/fake_data/factories/orders/ad_hoc.py index 29d6958..9fde451 100644 --- a/tests/db/fake_data/factories/orders/ad_hoc.py +++ b/tests/db/fake_data/factories/orders/ad_hoc.py @@ -186,9 +186,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory): ) @factory.post_generation - def post( # noqa:C901,WPS231 - obj, create, extracted, **kwargs, # noqa:B902,N805 - ): + def post(obj, _create, _extracted, **_kwargs): # noqa:B902,C901,N805 """Discard timestamps that occur after cancellation.""" if obj.cancelled: if obj.cancelled_at <= obj.restaurant_notified_at: diff --git a/tests/db/test_orders.py b/tests/db/test_orders.py index 653038a..5bf9e24 100644 --- a/tests/db/test_orders.py +++ b/tests/db/test_orders.py @@ -422,7 +422,7 @@ class TestProperties: @pytest.mark.db @pytest.mark.no_cover -def test_make_random_orders( # noqa:C901,WPS211,WPS213,WPS231 +def test_make_random_orders( # noqa:C901,WPS211,WPS213 db_session, make_address, make_courier, make_restaurant, make_order, ): """Sanity check the all the `make_*` fixtures.