wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

Function pagelanglinks has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
Open

    def pagelanglinks(
        self,
        page: pywikibot.Page,
        *,
        total: int | None = None,
Severity: Minor
Found in pywikibot/site/_generators.py - About 1 hr 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 editEntity has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
Open

    def editEntity(self,
                   entity: pywikibot.page.WikibaseEntity | dict,
                   data: dict,
                   bot: bool = True,
                   **kwargs) -> dict:
Severity: Minor
Found in pywikibot/site/_datasite.py - About 1 hr 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 test_RegexFilterPageGenerator has 32 lines of code (exceeds 30 allowed). Consider refactoring.
Open

    def test_RegexFilterPageGenerator(self):
        """Test RegexFilterPageGenerator."""
        self.assertFunction('RegexFilterPageGenerator')
        gen = pagegenerators.PagesFromTitlesGenerator(self.titles, self.site)
        gen = pagegenerators.RegexFilterPageGenerator(gen, '/doc')
Severity: Minor
Found in tests/pagegenerators_tests.py - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

                    if (removing and not self.conf.autonomous
                        or modifying and self.problemfound
                        or not old
                        or (self.conf.needlimit
                            and len(adding) + len(modifying)
    Severity: Major
    Found in scripts/interwiki.py - About 1 hr to fix

      Function put has 11 arguments (exceeds 7 allowed). Consider refactoring.
      Open

          def put(self, newtext: str,
      Severity: Major
      Found in pywikibot/page/_basepage.py - About 1 hr to fix

        Function save has 11 arguments (exceeds 7 allowed). Consider refactoring.
        Open

            def save(self,
        Severity: Major
        Found in pywikibot/page/_basepage.py - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                          if replaceit and trailing_chars:
                              newlink = f'[[{new_page_title}{section}]]{trailing_chars}'
                          elif replaceit or (new_page_title == link_text
                                             and not section):
                              newlink = f'[[{new_page_title}]]'
          Severity: Major
          Found in scripts/solve_disambiguation.py - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                        if force_interwiki \
                           or (allow_interwiki
                               and (self.site.family.name != target_family
                                    or self.site.code != target_code)):
                            if self.site.family.name not in (
            Severity: Major
            Found in pywikibot/page/_basepage.py - About 1 hr to fix

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

                  def _handle_supersetquery(self, value: str) -> HANDLER_GEN_TYPE:
                      """Handle `-supersetquery` argument."""
                      if not value:
                          value = pywikibot.input('Superset SQL query string:')
                      return SupersetPageGenerator(value, site=self.site)
              Severity: Major
              Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
              pywikibot/pagegenerators/_factory.py on lines 509..513
              pywikibot/pagegenerators/_factory.py on lines 623..627
              pywikibot/pagegenerators/_factory.py on lines 894..898

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

              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 4 locations. Consider refactoring.
              Open

                  def test_non_standard_version_sites(self):
                      """Test detection of non standard MediaWiki sites."""
                      for url in self.non_standard_version_sites:
                          with self.subTest(url=urlparse(url).netloc):
                              self.assertSite(url)
              Severity: Major
              Found in tests/site_detect_tests.py and 3 other locations - About 1 hr to fix
              tests/site_detect_tests.py on lines 106..110
              tests/site_detect_tests.py on lines 124..128
              tests/site_detect_tests.py on lines 130..134

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

              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 4 locations. Consider refactoring.
              Open

                  def test_unbalanced_headers(self):
                      """Test unbalanced section headers."""
                      text = ('text\n\n'
                              '====title===\n'
                              '==title 2===\n'
              Severity: Major
              Found in tests/textlib_tests.py and 3 other locations - About 1 hr to fix
              tests/textlib_tests.py on lines 1594..1605
              tests/textlib_tests.py on lines 1608..1618
              tests/textlib_tests.py on lines 1621..1636

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

              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 4 locations. Consider refactoring.
              Open

                  def _handle_file(self, value: str) -> HANDLER_GEN_TYPE:
                      """Handle `-file` argument."""
                      if not value:
                          value = pywikibot.input('Please enter the local file name:')
                      return TextIOPageGenerator(value, site=self.site)
              Severity: Major
              Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
              pywikibot/pagegenerators/_factory.py on lines 509..513
              pywikibot/pagegenerators/_factory.py on lines 894..898
              pywikibot/pagegenerators/_factory.py on lines 900..904

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

              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 4 locations. Consider refactoring.
              Open

                  def test_no_sites(self):
                      """Test detection of non-MediaWiki sites."""
                      for url in self.no_sites:
                          with self.subTest(url=urlparse(url).netloc):
                              self.assertNoSite(url)
              Severity: Major
              Found in tests/site_detect_tests.py and 3 other locations - About 1 hr to fix
              tests/site_detect_tests.py on lines 106..110
              tests/site_detect_tests.py on lines 118..122
              tests/site_detect_tests.py on lines 124..128

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

              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 4 locations. Consider refactoring.
              Open

                  def test_with_h1_and_h2_sections(self):
                      """Test for text having h1 and h2 sections."""
                      text = ('text\n\n'
                              '=first level=\n'
                              'foo\n'
              Severity: Major
              Found in tests/textlib_tests.py and 3 other locations - About 1 hr to fix
              tests/textlib_tests.py on lines 1608..1618
              tests/textlib_tests.py on lines 1621..1636
              tests/textlib_tests.py on lines 1666..1676

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

              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 unknown_parameters:
                      messages.append('Unknown parameter{s} "{params}".'
                                      .format(s='s' if len(unknown_parameters) > 1 else '',
                                              params='", "'.join(unknown_parameters)))
              Severity: Major
              Found in pywikibot/bot.py and 2 other locations - About 1 hr to fix
              pywikibot/bot.py on lines 925..928
              pywikibot/bot.py on lines 935..939

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

              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

              Function editpage has 11 arguments (exceeds 7 allowed). Consider refactoring.
              Open

                  def editpage(
              Severity: Major
              Found in pywikibot/site/_apisite.py - About 1 hr to fix

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

                    if missing_dependencies:
                        messages.append('Missing dependenc{s} "{deps}".'
                                        .format(
                                            s='ies' if len(missing_dependencies) > 1 else 'y',
                                            deps='", "'.join(missing_dependencies)))
                Severity: Major
                Found in pywikibot/bot.py and 2 other locations - About 1 hr to fix
                pywikibot/bot.py on lines 925..928
                pywikibot/bot.py on lines 931..934

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

                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

                Function load_topiclist has 11 arguments (exceeds 7 allowed). Consider refactoring.
                Open

                    def load_topiclist(self,
                Severity: Major
                Found in pywikibot/site/_extensions.py - About 1 hr to fix

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

                      def _handle_url(self, value: str) -> HANDLER_GEN_TYPE:
                          """Handle `-url` argument."""
                          if not value:
                              value = pywikibot.input('Please enter the URL:')
                          return TextIOPageGenerator(value, site=self.site)
                  Severity: Major
                  Found in pywikibot/pagegenerators/_factory.py and 3 other locations - About 1 hr to fix
                  pywikibot/pagegenerators/_factory.py on lines 623..627
                  pywikibot/pagegenerators/_factory.py on lines 894..898
                  pywikibot/pagegenerators/_factory.py on lines 900..904

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

                  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 4 locations. Consider refactoring.
                  Open

                      def test_standard_version_sites(self):
                          """Test detection of standard MediaWiki sites."""
                          for url in self.standard_version_sites:
                              with self.subTest(url=urlparse(url).netloc):
                                  self.assertSite(url)
                  Severity: Major
                  Found in tests/site_detect_tests.py and 3 other locations - About 1 hr to fix
                  tests/site_detect_tests.py on lines 118..122
                  tests/site_detect_tests.py on lines 124..128
                  tests/site_detect_tests.py on lines 130..134

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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language