wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

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

            (lambda v: dh(v, '%d000-vuosituhat',
                          lambda i: i - 1,
                          lambda ii: ii[0] + 1),
Severity: Major
Found in pywikibot/date.py and 4 other locations - About 50 mins to fix
pywikibot/date.py on lines 1180..1181
pywikibot/date.py on lines 1250..1251
pywikibot/date.py on lines 1347..1348
pywikibot/date.py on lines 1402..1403

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

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

    def delete_mod(self, reason: str) -> None:
        """Delete this topic through the Flow moderation system.

        :param reason: The reason for deleting this topic.
        """
Severity: Major
Found in pywikibot/flow.py and 8 other locations - About 50 mins to fix
pywikibot/flow.py on lines 349..356
pywikibot/flow.py on lines 358..365
pywikibot/flow.py on lines 367..374
pywikibot/flow.py on lines 386..393
pywikibot/flow.py on lines 582..589
pywikibot/flow.py on lines 591..598
pywikibot/flow.py on lines 600..607
pywikibot/flow.py on lines 609..616

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

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

    def suppress(self, reason: str) -> None:
        """Suppress this topic.

        :param reason: The reason for suppressing this topic.
        """
Severity: Major
Found in pywikibot/flow.py and 8 other locations - About 50 mins to fix
pywikibot/flow.py on lines 340..347
pywikibot/flow.py on lines 349..356
pywikibot/flow.py on lines 367..374
pywikibot/flow.py on lines 386..393
pywikibot/flow.py on lines 582..589
pywikibot/flow.py on lines 591..598
pywikibot/flow.py on lines 600..607
pywikibot/flow.py on lines 609..616

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

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

    def summarize(self, summary: str) -> None:
        """Summarize this topic.

        :param summary: The summary that will be added to the topic.
        """
Severity: Major
Found in pywikibot/flow.py and 8 other locations - About 50 mins to fix
pywikibot/flow.py on lines 340..347
pywikibot/flow.py on lines 349..356
pywikibot/flow.py on lines 358..365
pywikibot/flow.py on lines 367..374
pywikibot/flow.py on lines 582..589
pywikibot/flow.py on lines 591..598
pywikibot/flow.py on lines 600..607
pywikibot/flow.py on lines 609..616

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

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

        'sv': lambda v: dh(v, '%d000-talet (millennium)',
                           lambda i: i - 1, lambda ii: ii[0] + 1),
Severity: Major
Found in pywikibot/date.py and 4 other locations - About 50 mins to fix
pywikibot/date.py on lines 1180..1181
pywikibot/date.py on lines 1250..1251
pywikibot/date.py on lines 1297..1299
pywikibot/date.py on lines 1402..1403

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

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

    def treat(self, page):
        """Treat a single page."""
        if not page.exists():
            pywikibot.info('*** The sandbox is not existent, skipping.')
            return
Severity: Minor
Found in scripts/clean_sandbox.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 determine_type_target has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

        def determine_type_target(
            self,
            page: pywikibot.Page
        ) -> pywikibot.Page | None:
            """Return page to be categorized by type.
    Severity: Minor
    Found in scripts/category.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 __new__ has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
    Open

        def __new__(cls, name, bases, dct):
            """Create the new class."""
            def test_method(formatname):
    
                def testMapEntry(self):
    Severity: Minor
    Found in tests/date_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 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:
            - self.opt.isorphan
    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

    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

    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

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

        def __init__(
    Severity: Major
    Found in pywikibot/page/_wikibase.py - About 45 mins to fix

      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

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

              def get(self, force: bool = False) -> dict:
                  """Fetch all entity data and cache it.
          
                  :param force: override caching
                  :raise NoWikibaseEntityError: if this entity doesn't exist
          Severity: Minor
          Found in pywikibot/page/_wikibase.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
                  :type data: list or dict
          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 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 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

          Severity
          Category
          Status
          Source
          Language