wikimedia/pywikibot

View on GitHub

Showing 708 of 708 total issues

Avoid deeply nested control flow statements.
Open

                        if 'nochange' in data:  # in simulation mode
                            break

                        # Polls may not contain file key in response
                        file_key = data.get('filekey', file_key)
Severity: Major
Found in pywikibot/site/_upload.py - About 45 mins to fix

    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

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

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

                                  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

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                        if not self.sametitle(pageitem['title'],
                                              page.title(with_section=False)):
                            raise InconsistentTitleError(page, pageitem['title'])
            Severity: Major
            Found in pywikibot/site/_apisite.py and 2 other locations - About 45 mins to fix
            pywikibot/site/_extensions.py on lines 238..240
            pywikibot/site/_generators.py on lines 836..838

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                    ts1 = pywikibot.Timestamp(
                        year=2023, month=12, day=21, hour=13,
                        tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
            Severity: Major
            Found in tests/wikibase_tests.py and 4 other locations - About 45 mins to fix
            tests/wikibase_tests.py on lines 509..511
            tests/wikibase_tests.py on lines 579..581
            tests/wikibase_tests.py on lines 618..620
            tests/wikibase_tests.py on lines 627..629

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                    ts1 = pywikibot.Timestamp(
                        year=2023, month=12, day=21, hour=13,
                        tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
            Severity: Major
            Found in tests/wikibase_tests.py and 4 other locations - About 45 mins to fix
            tests/wikibase_tests.py on lines 509..511
            tests/wikibase_tests.py on lines 579..581
            tests/wikibase_tests.py on lines 594..596
            tests/wikibase_tests.py on lines 627..629

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                        if not self.sametitle(pagedata['title'],
                                              page.title(with_section=False)):
                            raise InconsistentTitleError(page, pagedata['title'])
            Severity: Major
            Found in pywikibot/site/_generators.py and 2 other locations - About 45 mins to fix
            pywikibot/site/_apisite.py on lines 1441..1443
            pywikibot/site/_extensions.py on lines 238..240

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                        if not self.sametitle(pageitem['title'],
                                              page.title(with_section=False)):
                            raise InconsistentTitleError(page, pageitem['title'])
            Severity: Major
            Found in pywikibot/site/_extensions.py and 2 other locations - About 45 mins to fix
            pywikibot/site/_apisite.py on lines 1441..1443
            pywikibot/site/_generators.py on lines 836..838

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                    ts4 = pywikibot.Timestamp(
                        year=2023, month=12, day=21, hour=13,
                        tzinfo=datetime.timezone(datetime.timedelta(hours=-6)))
            Severity: Major
            Found in tests/wikibase_tests.py and 4 other locations - About 45 mins to fix
            tests/wikibase_tests.py on lines 509..511
            tests/wikibase_tests.py on lines 579..581
            tests/wikibase_tests.py on lines 594..596
            tests/wikibase_tests.py on lines 618..620

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                    ts1 = pywikibot.Timestamp(
                        year=2022, month=12, day=21, hour=13,
                        tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
            Severity: Major
            Found in tests/wikibase_tests.py and 4 other locations - About 45 mins to fix
            tests/wikibase_tests.py on lines 579..581
            tests/wikibase_tests.py on lines 594..596
            tests/wikibase_tests.py on lines 618..620
            tests/wikibase_tests.py on lines 627..629

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                    ts1 = pywikibot.Timestamp(
                        year=2022, month=12, day=21, hour=13,
                        tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
            Severity: Major
            Found in tests/wikibase_tests.py and 4 other locations - About 45 mins to fix
            tests/wikibase_tests.py on lines 509..511
            tests/wikibase_tests.py on lines 594..596
            tests/wikibase_tests.py on lines 618..620
            tests/wikibase_tests.py on lines 627..629

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 43.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

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

                    Function report has 8 arguments (exceeds 7 allowed). Consider refactoring.
                    Open

                        def report(
                    Severity: Major
                    Found in scripts/checkimages.py - About 35 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language