wikimedia/pywikibot

View on GitHub

Showing 286 of 616 total issues

Function readOptions has a Cognitive Complexity of 31 (exceeds 10 allowed). Consider refactoring.
Open

    def readOptions(self, option: str) -> bool:
        """Read all commandline parameters for the global container."""
        arg, _, value = option.partition(':')
        if not arg.startswith('-'):
            return False
Severity: Minor
Found in scripts/interwiki.py - About 3 hrs 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

Function handle_args has a Cognitive Complexity of 31 (exceeds 10 allowed). Consider refactoring.
Open

def handle_args(args: Iterable[str] | None = None,
                do_help: bool = True) -> list[str]:
    """Handle global command line arguments and return the rest as a list.

    Takes the command line arguments as strings, processes all
Severity: Minor
Found in pywikibot/bot.py - About 3 hrs 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

Function title has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
Open

    def title(
        self,
        *,
        underscore: bool = False,
        with_ns: bool = True,
Severity: Minor
Found in pywikibot/page/_basepage.py - About 3 hrs 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

Function replace_links has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
Open

    def replace_links(self, text, linked_page, target_page):
        """Replace all source links by target."""
        mysite = pywikibot.Site()
        linktrail = mysite.linktrail()

Severity: Minor
Found in scripts/fixing_redirects.py - About 3 hrs 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

Function categorymembers has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
Open

    def categorymembers(
        self,
        category: pywikibot.Category,
        *,
        namespaces: NamespaceArgType = None,
Severity: Minor
Found in pywikibot/site/_generators.py - About 3 hrs 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

Function generator has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
Open

    def generator(self):
        """Inner generator.

        .. versionchanged:: 7.6
           changed from iterator method to generator property
Severity: Minor
Found in pywikibot/comms/eventstreams.py - About 3 hrs 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

Function deprecated_args has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
Open

def deprecated_args(**arg_pairs: str | None):
    """Decorator to declare multiple args deprecated.

    **Usage:**

Severity: Minor
Found in pywikibot/tools/_deprecate.py - About 3 hrs 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

Function remove_templates has a Cognitive Complexity of 29 (exceeds 10 allowed). Consider refactoring.
Open

    def remove_templates(self):
        """Understand if the page is blocked has the right template."""

        def understand_block():
            """Understand if the page is blocked has the right template."""
Severity: Minor
Found in scripts/blockpageschecker.py - About 3 hrs 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

Function batched has a Cognitive Complexity of 28 (exceeds 10 allowed). Consider refactoring.
Open

    def batched(iterable, n: int, *,
                strict: bool = False) -> Generator[tuple]:
        """Batch data from the *iterable* into tuples of length *n*.

        .. note:: The last batch may be shorter than *n* if *strict* is
Severity: Minor
Found in pywikibot/backports.py - About 3 hrs 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

Function main has a Cognitive Complexity of 28 (exceeds 10 allowed). Consider refactoring.
Open

def main(*args: str) -> None:
    """Process command line arguments and invoke bot.

    If args is an empty list, sys.argv is used.

Severity: Minor
Found in scripts/template.py - About 3 hrs 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

Function intersect_generators has a Cognitive Complexity of 28 (exceeds 10 allowed). Consider refactoring.
Open

def intersect_generators(*iterables, allow_duplicates: bool = False):
    """Generator of intersect iterables.

    Yield items only if they are yielded by all iterables. zip_longest
    is used to retrieve items from all iterables in parallel, so that
Severity: Minor
Found in pywikibot/tools/itertools.py - About 3 hrs 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

Function translateAndCapitalizeNamespaces has a Cognitive Complexity of 28 (exceeds 10 allowed). Consider refactoring.
Open

    def translateAndCapitalizeNamespaces(self, text: str) -> str:
        """Use localized namespace names.

        .. versionchanged:: 7.4
           No longer expect a specific namespace alias for File:
Severity: Minor
Found in pywikibot/cosmetic_changes.py - About 3 hrs 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

TestFactoryGenerator has 37 functions (exceeds 30 allowed). Consider refactoring.
Open

class TestFactoryGenerator(DefaultSiteTestCase):

    """Test pagegenerators.GeneratorFactory."""

    def test_combined_generator(self):
Severity: Minor
Found in tests/pagegenerators_tests.py - About 3 hrs to fix

    Function toJSON has a Cognitive Complexity of 27 (exceeds 10 allowed). Consider refactoring.
    Open

        def toJSON(self, diffto: dict | None = None) -> dict:
            """Create JSON suitable for Wikibase API.
    
            When diffto is provided, JSON representing differences
            to the provided data is created.
    Severity: Minor
    Found in pywikibot/page/_collections.py - About 3 hrs 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

    Function __enter__ has a Cognitive Complexity of 26 (exceeds 10 allowed). Consider refactoring.
    Open

        def __enter__(self):
            """Enter the context manager."""
            def detailed_show_warning(*args, **kwargs):
                """Replacement handler for warnings.showwarning."""
                warn_msg = warnings.WarningMessage(*args, **kwargs)
    Severity: Minor
    Found in tests/utils.py - About 2 hrs 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

    Function main has a Cognitive Complexity of 26 (exceeds 10 allowed). Consider refactoring.
    Open

    def main(*args: str) -> None:
        """Process command line arguments and invoke bot.
    
        If args is an empty list, sys.argv is used.
    
    
    Severity: Minor
    Found in scripts/transferbot.py - About 2 hrs 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

    Function find_file_on_commons has a Cognitive Complexity of 26 (exceeds 10 allowed). Consider refactoring.
    Open

        def find_file_on_commons(self, local_file_page):
            """Find filename on Commons."""
            for template_name, params in local_file_page.templatesWithParams():
                if template_name not in self.nc_templates:
                    continue
    Severity: Minor
    Found in scripts/nowcommons.py - About 2 hrs 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

    Function fromDBName has a Cognitive Complexity of 26 (exceeds 10 allowed). Consider refactoring.
    Open

        def fromDBName(  # noqa: N802
            dbname: str,
            site: BaseSite | None = None
        ) -> BaseSite:
            """Create a site from a database name using the sitematrix.
    Severity: Minor
    Found in pywikibot/site/_apisite.py - About 2 hrs 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

    File _datasite.py has 932 lines of code (exceeds 900 allowed). Consider refactoring.
    Open

    """Objects representing API interface to Wikibase site."""
    #
    # (C) Pywikibot team, 2012-2024
    #
    # Distributed under the terms of the MIT license.
    Severity: Major
    Found in pywikibot/site/_datasite.py - About 2 hrs to fix

      Function pywikibot_script_docstring_fixups has a Cognitive Complexity of 25 (exceeds 10 allowed). Consider refactoring.
      Open

      def pywikibot_script_docstring_fixups(app, what, name, obj, options, lines):
          """Pywikibot specific conversions."""
          from scripts.cosmetic_changes import warning
      
          if what != 'module' or 'scripts.' not in name:
      Severity: Minor
      Found in docs/conf.py - About 2 hrs 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

      Severity
      Category
      Status
      Source
      Language