pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.8k stars 1.58k forks source link

Reduce complexity of AdminModelConverter.convert in sqla/form.py #1425

Open pawl opened 7 years ago

pawl commented 7 years ago

I tried running flake8 --max-complexity 12 flask_admin and these were the results:

flask_admin/babel.py:1:1: C901 'TryExcept 1' is too complex (16)
flask_admin/contrib/fileadmin/__init__.py:1080:5: C901 'BaseFileAdmin.edit' is too complex (16)
flask_admin/contrib/mongoengine/ajax.py:90:1: C901 'process_ajax_references' is too complex (13)
flask_admin/contrib/peewee/view.py:334:5: C901 'ModelView.get_list' is too complex (14)
flask_admin/contrib/sqla/form.py:127:5: C901 'AdminModelConverter.convert' is too complex (29)
flask_admin/contrib/sqla/form.py:376:1: C901 'get_form' is too complex (14)
flask_admin/contrib/sqla/view.py:575:5: C901 'ModelView.scaffold_filters' is too complex (21)
flask_admin/model/base.py:1846:5: C901 'BaseModelView.index_view' is too complex (14)
flask_admin/model/widgets.py:97:5: C901 'XEditableWidget.get_kwargs' is too complex (17)

AdminModelConverter.convert in flask_admin/contrib/sqla/form.py really stands out with a complexity score of 29, so we definitely need to try to break it up into smaller functions.

ljluestc commented 1 year ago

To address this, you can refactor the AdminModelConverter.convert function by splitting it into smaller helper functions, each responsible for a specific sub-task or logical section. By doing so, you can reduce the complexity of the function and improve code readability