wikimedia/pywikibot

View on GitHub

Showing 286 of 616 total issues

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

      Avoid deeply nested control flow statements.
      Open

                                  if callable(ignore_warnings):
                                      restart = False
                                      if 'offset' not in data:
                                          # This is a result of a warning in the
                                          # first chunk. The chunk is not actually
      Severity: Major
      Found in pywikibot/site/_upload.py - About 45 mins to fix

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

            def merge_query_arguments(self,
                                      database_id: int | None = None,
                                      schema_name: str | None = None,
                                      site: BaseSite = None) -> tuple(int, str):
                """Determine and validate the database_id and schema_name.
        Severity: Minor
        Found in pywikibot/data/superset.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 ref_propid, reference in ref_grp['snaks'].items():
                                    for ref_index, ref_stat in enumerate(reference):
                                        target_ref_grp = claim.sources[ref_grp_idx]
                                        target_ref_prop = target_ref_grp[ref_propid]
                                        target_ref = target_ref_prop[ref_index]
        Severity: Major
        Found in pywikibot/page/_wikibase.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if self.sametitle(key, pagedata['title']):
                                          cache[pagedata['title']] = value
                                          break
                                  else:
          Severity: Major
          Found in pywikibot/site/_generators.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if page.title(with_ns=False) == self._base:
                                        what_links_here.remove(page)
                                        self._index = (page, what_links_here)
                                        break
            
            
            Severity: Major
            Found in pywikibot/proofreadpage.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if poll:
                                          # run a poll; not possible in first iteration
                                          assert file_key
                                          req = self.site.simple_request(
                                              action='upload',
              Severity: Major
              Found in pywikibot/site/_upload.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if hunk.reviewed == Hunk.PENDING:
                                            hunk.reviewed = \
                                                Hunk.APPR if choice == 'a' else Hunk.NOT_APPR
                                position = find_pending(0, position)
                Severity: Major
                Found in pywikibot/diff.py - About 45 mins to fix

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

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

                    Avoid deeply nested control flow statements.
                    Open

                                            if family == 'wiki':
                                                family = 'wikipedia'
                                            return pywikibot.Site(code, family)
                    Severity: Major
                    Found in pywikibot/site/_apisite.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                  if 'offset' in data:
                                                      new_offset = int(data['offset'])
                                                      if offset + len(chunk) != new_offset:
                                                          pywikibot.log(
                                                              f'Old offset: {offset}; Returned '
                      Severity: Major
                      Found in pywikibot/site/_upload.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

                                              with open(include) as g:
                                                  desc.append(re.sub(pattern[0], pattern[1], g.read()))
                                          else:  # pragma: no cover
                          Severity: Major
                          Found in setup.py - About 45 mins to fix

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

                            def replaceExcept(text: str,
                            Severity: Major
                            Found in pywikibot/textlib.py - About 45 mins to fix

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

                                  def addDirectedEdge(self, page: pywikibot.page.Page,
                                                      refPage: pywikibot.page.Page) -> None:
                                      """Add a directed edge from refPage to page."""
                                      assert self.graph is not None
                                      # if page was given as a hint, referrers would be [None]
                              Severity: Minor
                              Found in pywikibot/interwiki_graph.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

                              Consider simplifying this complex logical expression.
                              Open

                                      if '.' in t and (t in ('.', '..')
                                                       or t.startswith(('./', '../'))
                                                       or '/./' in t
                                                       or '/../' in t
                                                       or t.endswith(('/.', '/..'))):
                              Severity: Major
                              Found in pywikibot/page/_links.py - About 40 mins to fix

                                Consider simplifying this complex logical expression.
                                Open

                                        if arg == 'noauto':
                                            self.auto = False
                                        elif arg == 'hint':
                                            self.hints.append(value)
                                        elif arg == 'hintfile':
                                Severity: Major
                                Found in scripts/interwiki.py - About 40 mins to fix

                                  Consider simplifying this complex logical expression.
                                  Open

                                              if new_page_title == link_text and not section \
                                                 or self.opt.overwrite:
                                                  newlink = f'[[{new_page_title}]]'
                                              # check if we can create a link with trailing characters instead of
                                              # a pipelink
                                  Severity: Major
                                  Found in scripts/fixing_redirects.py - About 40 mins to fix

                                    Consider simplifying this complex logical expression.
                                    Open

                                            if opt == 'start':
                                                options[opt] = value or pywikibot.input(
                                                    'From which title do you want to continue?')
                                            elif opt == 'save':
                                                options[opt] = value or pywikibot.input(
                                    Severity: Major
                                    Found in scripts/parser_function_count.py - About 40 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language