wikimedia/pywikibot

View on GitHub

Showing 286 of 616 total issues

Function display_references has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
Open

    def display_references(self) -> None:
        """Display pages that link to the current page, sorted per namespace.

        Number of pages to display per namespace is provided by:
        - self.opt.isorphan
Severity: Minor
Found in scripts/delete.py - About 45 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

Function main has a Cognitive Complexity of 13 (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/data_ingestion.py - About 45 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

Function isTitleExcepted has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
Open

    def isTitleExcepted(self, title, exceptions=None) -> bool:
        """Return True if one of the exceptions applies for the given title."""
        if exceptions is None:
            exceptions = self.exceptions
        if 'title' in exceptions:
Severity: Minor
Found in scripts/replace.py - About 45 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

Function __init__ has 9 arguments (exceeds 7 allowed). Consider refactoring.
Open

    def __init__(
Severity: Major
Found in pywikibot/page/_wikibase.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            with self.assertRaises(AttributeError):
                                exec(f'self.namespaces.{name}.id')
    
    
    Severity: Major
    Found in tests/namespace_tests.py - About 45 mins to fix

      Function testLinks has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

          def testLinks(self):
              """Test the different types of links from a page."""
              mainpage = self.get_mainpage()
              for p in mainpage.linkedPages():
                  self.assertIsInstance(p, pywikibot.Page)
      Severity: Minor
      Found in tests/page_tests.py - About 45 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

      Avoid deeply nested control flow statements.
      Open

                              if total == 0:
                                  return
      
      
      Severity: Major
      Found in pywikibot/page/_category.py - About 45 mins to fix

        Function get has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def get(self, force: bool = False) -> dict:
                """Fetch all entity data and cache it.
        
                :param force: override caching
                :raise NoWikibaseEntityError: if this entity doesn't exist
        Severity: Minor
        Found in pywikibot/page/_wikibase.py - About 45 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

        Function normalizeData has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def normalizeData(cls, data) -> dict:
                """Helper function to expand data into the Wikibase API structure.
        
                :param data: Data to normalize
                :type data: list or dict
        Severity: Minor
        Found in pywikibot/page/_collections.py - About 45 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

        Function parse_key has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def parse_key(self):
                """Parse the key loaded from the cache entry."""
                # find the start of the first parameter
                start = self.key.index('(')
                # find the end of the first object
        Severity: Minor
        Found in scripts/maintenance/cache.py - About 45 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

        Function report has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def report(
                self,
                newtext,
                image_to_report,
                notification=None,
        Severity: Minor
        Found in scripts/checkimages.py - About 45 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

        Avoid deeply nested control flow statements.
        Open

                                if key == '@metadata':
                                    continue
                                self.assertTrue(
        Severity: Major
        Found in tests/l10n_tests.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if tu:
                                      # no changes needed, better to revert the old text.
                                      text = oldtext
                              else:
          Severity: Major
          Found in scripts/blockpageschecker.py - About 45 mins to fix

            Function check_image_on_commons has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
            Open

                def check_image_on_commons(self) -> bool:
                    """Checking if the file is on commons."""
                    pywikibot.info(f'Checking if [[{self.image_name}]] is on commons...')
                    try:
                        hash_found = self.image.latest_file_info.sha1
            Severity: Minor
            Found in scripts/checkimages.py - About 45 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

            Avoid deeply nested control flow statements.
            Open

                                    if tu:
                                        # no changes needed, better to revert the old text.
                                        text = oldtext
                                else:
            Severity: Major
            Found in scripts/blockpageschecker.py - About 45 mins to fix

              Function set_redirect_target has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
              Open

                  def set_redirect_target(
                      self,
                      target_page: pywikibot.Page | str,
                      create: bool = False,
                      force: bool = False,
              Severity: Minor
              Found in pywikibot/page/_page.py - About 45 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

              Function getPDFTitle has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
              Open

                  def getPDFTitle(ref, response) -> None:
                      """Use pdfinfo to retrieve title from a PDF."""
                      # pdfinfo is Unix-only
                      pywikibot.info('Reading PDF file...')
                      infile = None
              Severity: Minor
              Found in scripts/reflinks.py - About 45 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

              Function get has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
              Open

                  def get(self, force: bool = False) -> dict:
                      """Fetch all MediaInfo entity data and cache it.
              
                      .. note:: dicts returned by this method are references to content
                         of this entity and their modifying may indirectly cause
              Severity: Minor
              Found in pywikibot/page/_wikibase.py - About 45 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

              Function watchlist_revs has 9 arguments (exceeds 7 allowed). Consider refactoring.
              Open

                  def watchlist_revs(
              Severity: Major
              Found in pywikibot/site/_generators.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        for qual_index, qual_statement in enumerate(qualifier):
                                            target_qual_prop = claim.qualifiers[qual_propid]
                                            target_qual = target_qual_prop[qual_index]
                                            target_qual.hash = qual_statement['hash']
                                    updated_references = statement.get('references', [])
                Severity: Major
                Found in pywikibot/page/_wikibase.py - About 45 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language