wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

Function check_page has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
Open

    def check_page(self, pagename) -> None:
        """Check one page."""
        pywikibot.info('\nChecking ' + pagename)
        page1 = Page(self.original, pagename)
        txt1 = page1.text
Severity: Minor
Found in scripts/replicate_wiki.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 newest_pages has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
Open

    def newest_pages(
        self,
        total: int | None = None
    ) -> Generator[Page, None, None]:
        """Return pages in a category ordered by the creation date.
Severity: Minor
Found in pywikibot/page/_category.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 get_best_claim has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
Open

    def get_best_claim(self, prop: str):
        """Return the first best Claim for this page.

        Return the first 'preferred' ranked Claim specified by Wikibase
        property or the first 'normal' one otherwise.
Severity: Minor
Found in pywikibot/page/_page.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 main has a Cognitive Complexity of 16 (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/templatecount.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 title has 13 arguments (exceeds 7 allowed). Consider refactoring.
Open

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

    Function color_line has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def color_line(self, line: str, line_ref: str | None = None) -> str:
            """Color line characters.
    
            If line_ref is None, the whole line is colored.
            If line_ref[i] is not blank, line[i] is colored.
    Severity: Minor
    Found in pywikibot/diff.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 __init__ has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def __init__(self, fromurl, **kwargs) -> None:
            """Initializer.
    
            :raises pywikibot.exceptions.ServerError: a server error
                occurred while loading the site
    Severity: Minor
    Found in pywikibot/site_detect.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 _wbset_action has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def _wbset_action(self, itemdef, action: str, action_data,
                          **kwargs) -> dict:
            """Execute wbset{action} on a Wikibase entity.
    
            Supported actions are:
    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

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

        def test_match_msg(self):
            """Test pages with {{msg:..}}."""
            pages = self.generator('Foo', 'dummy-template.xml')
            self.assertLength(pages, 1)
            self.assertPageTitlesEqual(pages, ['Fake page with msg'],
    Severity: Major
    Found in tests/template_bot_tests.py and 2 other locations - About 1 hr to fix
    tests/template_bot_tests.py on lines 87..93
    tests/template_bot_tests.py on lines 95..101

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

    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_match_unnecessary_template_prefix(self):
            """Test pages with {{template:..}}."""
            pages = self.generator('Bar', 'dummy-template.xml')
            self.assertLength(pages, 1)
            self.assertPageTitlesEqual(
    Severity: Major
    Found in tests/template_bot_tests.py and 2 other locations - About 1 hr to fix
    tests/template_bot_tests.py on lines 80..85
    tests/template_bot_tests.py on lines 95..101

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

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

    def input_sections(variant: str,
                       sections: list[_ConfigSection],
                       skip: Callable | None = None,
                       force: bool = False,
                       default: str = 'n') -> list[str]:
    Severity: Minor
    Found in pywikibot/scripts/generate_user_files.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 _fetch has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def _fetch(self, modules: set | frozenset) -> None:
            """Get paraminfo for multiple modules without initializing beforehand.
    
            :param modules: API modules to load and which haven't been loaded yet.
            """
    Severity: Minor
    Found in pywikibot/data/api/_paraminfo.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 stream_output has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def stream_output(self, text, targetStream=None) -> None:
            """Output text to a stream.
    
            If a character can't be displayed in the encoding used by the user's
            terminal, it will be replaced with a question mark or by a
    Severity: Minor
    Found in pywikibot/userinterfaces/terminal_interface_base.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 allpages has 13 arguments (exceeds 7 allowed). Consider refactoring.
    Open

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

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

          def parse(self) -> Iterator[XmlEntry]:
              """Generator using ElementTree iterparse function.
      
              .. versionchanged:: 7.2
                 if a ParseError occurs it can be handled by the callable
      Severity: Minor
      Found in pywikibot/xmlreader.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

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

          def test_nested_match(self):
              """Test pages with one match inside another template."""
              pages = self.generator('boo', 'dummy-template.xml')
              self.assertLength(pages, 1)
              self.assertPageTitlesEqual(
      Severity: Major
      Found in tests/template_bot_tests.py and 2 other locations - About 1 hr to fix
      tests/template_bot_tests.py on lines 80..85
      tests/template_bot_tests.py on lines 87..93

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

      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 main has 36 lines of code (exceeds 30 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/transferbot.py - About 1 hr to fix

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

            def __init__(self, cat_title: str | None, list_title: str | None,
        Severity: Major
        Found in scripts/category.py - About 1 hr to fix

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

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

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

                def __init__(self,
            Severity: Major
            Found in pywikibot/_wbtypes.py - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language