wikimedia/pywikibot

View on GitHub

Showing 708 of 708 total issues

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 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
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 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

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 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

    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

    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

      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

      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 apply_replacements has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

          def apply_replacements(self, original_text, applied, page=None):
              """
              Apply all replacements to the given text.
      
              :rtype: str, set
      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

      Avoid deeply nested control flow statements.
      Open

                          if seq.getTarget().getID() in instance_id:
                              for lang in item.labels:  # Search all languages
                                  # Ignore label case and accents
                                  if (unidecode(item_name.lower())
                                          == unidecode(item.labels[lang].lower())):
      Severity: Major
      Found in scripts/create_isbn_edition.py - About 45 mins to fix

        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

        Avoid deeply nested control flow statements.
        Open

                                while result <= maxlen:
                                    result += 1
                                    final = redirects[final]
        
                        # only yield multiple or broken redirects
        Severity: Major
        Found in scripts/redirect.py - About 45 mins to fix

          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:
          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

          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

            Avoid deeply nested control flow statements.
            Open

                                    if hunk.reviewed == Hunk.PENDING:
                                        hunk.reviewed = Hunk.NOT_APPR
                        elif choice in ['a', 'd']:
            Severity: Major
            Found in pywikibot/diff.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if force:
                                          raise ValueError(
                                              f'{default!r} is not a valid Option for '
                                              f'{removeprefix(output, question).lstrip()}')
              
              
              Severity: Major
              Found in pywikibot/userinterfaces/terminal_interface_base.py - About 45 mins to fix

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

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

                  Avoid deeply nested control flow statements.
                  Open

                                              if error.code == 'stashfailed' \
                                                      and 'offset' in error.other:
                                                  # TODO: Ask MediaWiki to change this
                                                  # ambiguous error code.
                  
                  
                  Severity: Major
                  Found in pywikibot/site/_upload.py - About 45 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language