wikimedia/pywikibot

View on GitHub

Showing 744 of 744 total issues

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

class TestPartiallyQualifiedImplicitLinkDifferentFamilyParser(LinkTestCase):

    """Test partially qualified links to different family."""

    family = 'wikipedia'
Severity: Major
Found in tests/link_tests.py and 2 other locations - About 1 day to fix
tests/link_tests.py on lines 316..343
tests/link_tests.py on lines 543..570

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

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

    def __new__(cls, name, bases, dct):
        """Create the new class."""
        def test_execution(script_name, args=None):
            if args is None:
                args = []
Severity: Minor
Found in tests/script_tests.py - About 1 day 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

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

    def test_XmlDumpEarliestRev(self):
        """Test loading the earliest revision."""
        pages = get_entries('article-pear.xml', revisions='earliest')
        self.assertLength(pages, 1)
        self.assertEqual('Automated conversion', pages[0].comment)
Severity: Major
Found in tests/xmlreader_tests.py and 2 other locations - About 1 day to fix
tests/xmlreader_tests.py on lines 43..56
tests/xmlreader_tests.py on lines 69..78

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

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

    def test_XmlDumpLatestRev(self):
        """Test loading the latest revision."""
        pages = get_entries('article-pear.xml', revisions='latest')
        self.assertLength(pages, 1)
        self.assertEqual('sp', pages[0].comment)
Severity: Major
Found in tests/xmlreader_tests.py and 2 other locations - About 1 day to fix
tests/xmlreader_tests.py on lines 43..56
tests/xmlreader_tests.py on lines 58..67

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

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

    def test_XmlDumpFirstFoundRev(self):
        """Test loading the first found revision.

        To be deprecated.
        :phab: `T340804`
Severity: Major
Found in tests/xmlreader_tests.py and 2 other locations - About 1 day to fix
tests/xmlreader_tests.py on lines 58..67
tests/xmlreader_tests.py on lines 69..78

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

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

    def _check_bot_may_edit(self, module: str | None = None) -> bool:
        """A botMayEdit helper method.

        :param module: The module name to be restricted. Defaults to
            :func:`pywikibot.calledModuleName`.
Severity: Minor
Found in pywikibot/page/_basepage.py - About 1 day 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

GeneratorFactory has 71 functions (exceeds 30 allowed). Consider refactoring.
Open

class GeneratorFactory:

    """Process command line arguments and return appropriate page generator.

    This factory is responsible for processing command line arguments
Severity: Major
Found in pywikibot/pagegenerators/_factory.py - About 1 day to fix

    Function main has a Cognitive Complexity of 59 (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/upload.py - About 1 day 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

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

    class TestFullyQualifiedImplicitLinkSameFamilyParser(LinkTestWikiEn):
    
        """Link tests."""
    
        def test_fully_qualified_NS0_code(self):
    Severity: Major
    Found in tests/link_tests.py and 3 other locations - About 1 day to fix
    tests/link_tests.py on lines 295..313
    tests/link_tests.py on lines 369..387
    tests/link_tests.py on lines 613..631

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

    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

    class TestFullyQualifiedExplicitLinkSameFamilyParser(LinkTestWikiEn):
    
        """Link tests."""
    
        def test_fully_qualified_NS0_code(self):
    Severity: Major
    Found in tests/link_tests.py and 3 other locations - About 1 day to fix
    tests/link_tests.py on lines 295..313
    tests/link_tests.py on lines 613..631
    tests/link_tests.py on lines 664..682

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

    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

    class TestPartiallyQualifiedExplicitLinkDifferentCodeParser(LinkTestWikiEn):
    
        """Link tests."""
    
        def test_partially_qualified_NS0_family(self):
    Severity: Major
    Found in tests/link_tests.py and 3 other locations - About 1 day to fix
    tests/link_tests.py on lines 369..387
    tests/link_tests.py on lines 613..631
    tests/link_tests.py on lines 664..682

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

    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

    class TestPartiallyQualifiedImplicitLinkDifferentCodeParser(LinkTestWikiEn):
    
        """Test partially qualified links to different code."""
    
        def test_partially_qualified_NS0_family(self):
    Severity: Major
    Found in tests/link_tests.py and 3 other locations - About 1 day to fix
    tests/link_tests.py on lines 295..313
    tests/link_tests.py on lines 369..387
    tests/link_tests.py on lines 664..682

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

    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

    File aspects.py has 1151 lines of code (exceeds 900 allowed). Consider refactoring.
    Open

    """
    Test aspects to allow fine grained control over what tests are executed.
    
    Several parts of the test infrastructure are implemented as mixins,
    such as API result caching and excessive test durations.
    Severity: Major
    Found in tests/aspects.py - About 1 day to fix

      Function main has a Cognitive Complexity of 56 (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/transwikiimport.py - About 7 hrs 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

      File solve_disambiguation.py has 1115 lines of code (exceeds 900 allowed). Consider refactoring.
      Open

      #!/usr/bin/env python3
      """
      Script to help a human solve disambiguations by presenting a set of options.
      
      Specify the disambiguation page on the command line.
      Severity: Major
      Found in scripts/solve_disambiguation.py - About 7 hrs to fix

        File transliteration.py has 1101 lines of code (exceeds 900 allowed). Consider refactoring.
        Open

        """Module to transliterate text."""
        #
        # (C) Pywikibot team, 2006-2024
        #
        # Distributed under the terms of the MIT license.
        Severity: Major
        Found in pywikibot/userinterfaces/transliteration.py - About 6 hrs to fix

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

              def test_musical_notation_edit(self):
                  """Attempt adding a musical notation claim with valid input."""
                  testsite = self.get_repo()
                  item = self._clean_item(testsite, 'P88936')
          
          
          Severity: Major
          Found in tests/wikibase_edit_tests.py and 2 other locations - About 6 hrs to fix
          tests/wikibase_edit_tests.py on lines 260..274
          tests/wikibase_edit_tests.py on lines 361..375

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

          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

              def test_math_edit(self):
                  """Attempt adding a math claim with valid input."""
                  testsite = self.get_repo()
                  item = self._clean_item(testsite, 'P717')
          
          
          Severity: Major
          Found in tests/wikibase_edit_tests.py and 2 other locations - About 6 hrs to fix
          tests/wikibase_edit_tests.py on lines 361..375
          tests/wikibase_edit_tests.py on lines 416..431

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

          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

              def test_identifier_edit(self):
                  """Attempt adding an external identifier claim with valid input."""
                  testsite = self.get_repo()
                  item = self._clean_item(testsite, 'P718')
          
          
          Severity: Major
          Found in tests/wikibase_edit_tests.py and 2 other locations - About 6 hrs to fix
          tests/wikibase_edit_tests.py on lines 260..274
          tests/wikibase_edit_tests.py on lines 416..431

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

          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

          File proofreadpage.py has 1082 lines of code (exceeds 900 allowed). Consider refactoring.
          Open

          """
          Objects used with ProofreadPage Extension.
          
          This module includes objects:
          
          
          Severity: Major
          Found in pywikibot/proofreadpage.py - About 6 hrs to fix
            Severity
            Category
            Status
            Source
            Language