wikimedia/pywikibot

View on GitHub

Showing 742 of 742 total issues

Function parse has a Cognitive Complexity of 46 (exceeds 10 allowed). Consider refactoring.
Open

    def parse(self):
        """
        Parse wikitext of the link.

        Called internally when accessing attributes.
Severity: Minor
Found in pywikibot/page/_links.py - About 6 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

Function main has a Cognitive Complexity of 43 (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/protect.py - About 5 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

Function package_versions has a Cognitive Complexity of 43 (exceeds 10 allowed). Consider refactoring.
Open

def package_versions(
    modules: list[str] | None = None,
    builtins: bool | None = False,
    standard_lib: bool | None = None,
):
Severity: Minor
Found in pywikibot/version.py - About 5 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

Function get_base_dir has a Cognitive Complexity of 43 (exceeds 10 allowed). Consider refactoring.
Open

def get_base_dir(test_directory: str | None = None,
                 config_file: str = 'user-config.py') -> str:
    r"""Return the directory in which user-specific information is stored.

    This is determined in the following order:
Severity: Minor
Found in pywikibot/config.py - About 5 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

Function getCombinedGenerator has a Cognitive Complexity of 42 (exceeds 10 allowed). Consider refactoring.
Open

    def getCombinedGenerator(self,  # noqa: N802
                             gen: OPT_GENERATOR_TYPE = None,
                             preload: bool = False) -> OPT_GENERATOR_TYPE:
        """Return the combination of all accumulated generators.

Severity: Minor
Found in pywikibot/pagegenerators/_factory.py - About 5 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

Function submit has a Cognitive Complexity of 42 (exceeds 10 allowed). Consider refactoring.
Open

    def submit(self, request, result, data_result: str | None,
               ignore_warnings, ignore_all_warnings, report_success,
               file_key) -> bool:
        """Submit request and return whether upload was successful."""
        # some warning keys have been changed
Severity: Minor
Found in pywikibot/site/_upload.py - About 5 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 site_tests.py has 1048 lines of code (exceeds 900 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
"""Tests for the site module."""
#
# (C) Pywikibot team, 2008-2023
#
Severity: Major
Found in tests/site_tests.py - About 5 hrs to fix

    Function process_entries has a Cognitive Complexity of 41 (exceeds 10 allowed). Consider refactoring.
    Open

    def process_entries(cache_path, func, use_accesstime: bool | None = None,
                        output_func=None, action_func=None, *,
                        tests: int | None = None):
        """Check the contents of the cache.
    
    
    Severity: Minor
    Found in scripts/maintenance/cache.py - About 5 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

    Function run has a Cognitive Complexity of 41 (exceeds 10 allowed). Consider refactoring.
    Open

        def run(self) -> None:
            """Run bot."""
            def convert_from_bytes(total_bytes):
                for unit in ['B', 'K', 'M', 'G', 'T']:
                    if abs(total_bytes) < 1024:
    Severity: Minor
    Found in scripts/download_dump.py - About 5 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

    Function get_item_list has a Cognitive Complexity of 41 (exceeds 10 allowed). Consider refactoring.
    Open

    def get_item_list(item_name: str, instance_id):
        """Get list of items by name, belonging to an instance (list).
    
        :param item_name: Item name (case sensitive)
        :param instance_id: Instance ID (string, set, or list)
    Severity: Minor
    Found in scripts/create_isbn_edition.py - About 5 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

    Function preloadpages has a Cognitive Complexity of 41 (exceeds 10 allowed). Consider refactoring.
    Open

        def preloadpages(
            self,
            pagelist: Iterable[pywikibot.Page],
            *,
            groupsize: int | None = None,
    Severity: Minor
    Found in pywikibot/site/_generators.py - About 5 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

    Function translate has a Cognitive Complexity of 41 (exceeds 10 allowed). Consider refactoring.
    Open

    def translate(
        page=None,
        hints=(),
        auto: bool = True,
        removebrackets: bool = False,
    Severity: Minor
    Found in pywikibot/titletranslate.py - About 5 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

    Function process has a Cognitive Complexity of 40 (exceeds 10 allowed). Consider refactoring.
    Open

        def process(self, text):
            """Process the page."""
            # keys are ref groups
            # values are a dict where :
            #   keys are ref content
    Severity: Minor
    Found in scripts/reflinks.py - About 5 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

    Function deprecated_args has a Cognitive Complexity of 40 (exceeds 10 allowed). Consider refactoring.
    Open

    def deprecated_args(**arg_pairs):
        """Decorator to declare multiple args deprecated.
    
        Usage:
    
    
    Severity: Minor
    Found in pywikibot/tools/_deprecate.py - About 5 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

    Function toJSON has a Cognitive Complexity of 39 (exceeds 10 allowed). Consider refactoring.
    Open

        def toJSON(self) -> dict:
            """Create dict suitable for the MediaWiki API."""
            data = {
                'mainsnak': {
                    'snaktype': self.snaktype,
    Severity: Minor
    Found in pywikibot/page/_wikibase.py - About 5 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 _generators.py has 1027 lines of code (exceeds 900 allowed). Consider refactoring.
    Open

    """Page filter generators provided by the pagegenerators module."""
    #
    # (C) Pywikibot team, 2008-2023
    #
    # Distributed under the terms of the MIT license.
    Severity: Major
    Found in pywikibot/pagegenerators/_generators.py - About 5 hrs to fix

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

          def test_claim_eq_simple_different_value(self):
              """
              Test comparing two claims.
      
              If they have the same property and different values,
      Severity: Major
      Found in tests/wikibase_tests.py and 2 other locations - About 5 hrs to fix
      tests/wikibase_tests.py on lines 1749..1761
      tests/wikibase_tests.py on lines 1809..1822

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

      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_claim_eq_simple(self):
              """
              Test comparing two claims.
      
              If they have the same property and value, they are equal.
      Severity: Major
      Found in tests/wikibase_tests.py and 2 other locations - About 5 hrs to fix
      tests/wikibase_tests.py on lines 1763..1776
      tests/wikibase_tests.py on lines 1809..1822

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

      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_claim_eq_simple_different_property(self):
              """
              Test comparing two claims.
      
              If they have the same value and different properties,
      Severity: Major
      Found in tests/wikibase_tests.py and 2 other locations - About 5 hrs to fix
      tests/wikibase_tests.py on lines 1749..1761
      tests/wikibase_tests.py on lines 1763..1776

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

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

          def parse_page_tuples(self, wikitext, user=None):
              """Parse page details apart from 'user:' for use."""
              whitelist = defaultdict(set)
      
              current_user = False
      Severity: Minor
      Found in scripts/patrol.py - About 4 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

      Severity
      Category
      Status
      Source
      Language