wikimedia/pywikibot

View on GitHub
scripts/solve_disambiguation.py

Summary

Maintainability
C
1 day
Test Coverage

File solve_disambiguation.py has 1061 lines of code (exceeds 900 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
"""
Script to help a human solve disambiguations by presenting a set of options.

Specify the disambiguation page on the command line.
Severity: Major
Found in scripts/solve_disambiguation.py - About 5 hrs to fix

    Function treat_disamb_only has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
    Open

        def treat_disamb_only(self, ref_page, disamb_page) -> str:
            """Resolve the links to disamb_page but don't look for its redirects.
    
            :param disamb_page: the disambiguation page or redirect we don't want
                anything to link to
    Severity: Minor
    Found in scripts/solve_disambiguation.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Consider simplifying this complex logical expression.
    Open

                    if replaceit and trailing_chars:
                        newlink = f'[[{new_page_title}{section}]]{trailing_chars}'
                    elif replaceit or (new_page_title == link_text
                                       and not section):
                        newlink = f'[[{new_page_title}]]'
    Severity: Major
    Found in scripts/solve_disambiguation.py - About 1 hr to fix

      Function __iter__ has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Open

          def __iter__(self) -> Generator[pywikibot.Page, None, None]:
              """Yield pages."""
              # TODO: start yielding before all referring pages have been found
              refs = list(self.page.getReferences(with_template_inclusion=False,
                                                  namespaces=0 if self.main_only
      Severity: Minor
      Found in scripts/solve_disambiguation.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      TODO found
      Open

              # TODO: start yielding before all referring pages have been found
      Severity: Minor
      Found in scripts/solve_disambiguation.py by fixme

      TODO found
      Open

              # TODO: break this function up into subroutines!
      Severity: Minor
      Found in scripts/solve_disambiguation.py by fixme

      TODO found
      Open

                      # TODO: Output context on each question
      Severity: Minor
      Found in scripts/solve_disambiguation.py by fixme

      There are no issues that match your filters.

      Category
      Status