Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

McCabe complexity checker for Python

License

NotificationsYou must be signed in to change notification settings

PyCQA/mccabe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ned's script to check McCabe complexity.

This module provides a plugin forflake8, the Python code checker.

Installation

You can install, upgrade, or uninstallmccabe with these commands:

$ pip install mccabe$ pip install --upgrade mccabe$ pip uninstall mccabe

Standalone script

The complexity checker can be used directly:

$ python -m mccabe --min 5 mccabe.py("185:1: 'PathGraphingAstVisitor.visitIf'", 5)("71:1: 'PathGraph.to_dot'", 5)("245:1: 'McCabeChecker.run'", 5)("283:1: 'main'", 7)("203:1: 'PathGraphingAstVisitor.visitTryExcept'", 5)("257:1: 'get_code_complexity'", 5)

Plugin for Flake8

When bothflake8 2+ andmccabe are installed, the plugin isavailable inflake8:

$ flake8 --version2.0 (pep8: 1.4.2, pyflakes: 0.6.1, mccabe: 0.2)

By default the plugin is disabled. Use the--max-complexity switch toenable it. It will emit a warning if the McCabe complexity of a function ishigher than the provided value:

$ flake8 --max-complexity 10 coolproject...coolproject/mod.py:1204:1: C901 'CoolFactory.prepare' is too complex (14)

This feature is quite useful for detecting over-complex code. According to McCabe,anything that goes beyond 10 is too complex.

Flake8 has many features that mccabe does not provide. Flake8 allows users toignore violations reported by plugins with# noqa. Read more about this intheir documentation.To silence violations reported bymccabe, place your# noqa: C901 onthe function definition line, where the error is reported for (possibly adecorator).

Links

Changes

0.7.0 - 2022-01-23

  • Drop support for all versions of Python lower than 3.6
  • Add support for Python 3.8, 3.9, and 3.10
  • Fix option declaration for Flake8

0.6.1 - 2017-01-26

  • Fix signature forPathGraphingAstVisitor.default to match the signatureforASTVisitor

0.6.0 - 2017-01-23

  • Add support for Python 3.6
  • Fix handling for missing statement types

0.5.3 - 2016-12-14

  • Report actual column number of violation instead of the start of the line

0.5.2 - 2016-07-31

  • When opening files ourselves, make sure we always name the file variable

0.5.1 - 2016-07-28

  • Set default maximum complexity to -1 on the class itself

0.5.0 - 2016-05-30

  • PyCon 2016 PDX release
  • Add support for Flake8 3.0

0.4.0 - 2016-01-27

  • Stop testing on Python 3.2
  • Add support for async/await keywords on Python 3.5 from PEP 0492

0.3.1 - 2015-06-14

  • Includetest_mccabe.py in releases.
  • Always coerce themax_complexity value from Flake8's entry-point to aninteger.

0.3 - 2014-12-17

  • Computation was wrong: the mccabe complexity starts at 1, not 2.
  • Themax-complexity value is now inclusive. E.g.: if thevalue is 10 and the reported complexity is 10, then it passes.
  • Add tests.

0.2.1 - 2013-04-03

  • Do not requiresetuptools in setup.py. It works around an issuewithpip and Python 3.

0.2 - 2013-02-22

  • Rename project tomccabe.
  • Provideflake8.extension setuptools entry point.
  • Readmax-complexity from the configuration file.
  • Rename argumentmin_complexity tothreshold.

0.1 - 2013-02-11

  • First release

[8]ページ先頭

©2009-2025 Movatter.jp