wikimedia/pywikibot

View on GitHub

Showing 708 of 708 total issues

Function test_WbTime_normalization has 37 lines of code (exceeds 30 allowed). Consider refactoring.
Open

    def test_WbTime_normalization(self):
        """Test WbTime normalization."""
        repo = self.get_repo()
        # flake8 is being annoying, so to reduce line length, I'll make
        # some aliases here
Severity: Minor
Found in tests/wikibase_tests.py - About 1 hr to fix

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

        def guess_reason_for_deletion(self, page):
            """Find a default reason for speedy deletion."""
            # TODO: The following check loads the page 2 times.
            # Find a better way to do it.
            if page.isTalkPage() and (page.toggleTalkPage().isRedirectPage()
    Severity: Minor
    Found in scripts/speedy_delete.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 move_contents has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def move_contents(self, old_cat_title: str, new_cat_title: str,
                          edit_summary: str) -> tuple[int, int]:
            """The worker function that moves pages out of oldCat into newCat."""
            old_cat = pywikibot.Category(self.site, self.catprefix + old_cat_title)
            new_cat = pywikibot.Category(self.site, self.catprefix + new_cat_title)
    Severity: Minor
    Found in scripts/category_redirect.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_fromPage_noitem has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def _test_fromPage_noitem(self, link):
            """Helper function to test a page without an associated item.
    
            It tests two of the ways to fetch an item:
            1. the Page already has props, which should contain an item id if
    Severity: Minor
    Found in tests/wikibase_tests.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 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]:
            """
    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 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

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

    def _extract_plural(lang: str, message: str, parameters: Mapping[str, int]
                        ) -> str:
        """Check for the plural variants in message and replace them.
    
        :param message: the message to be replaced
    Severity: Minor
    Found in pywikibot/i18n.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 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 authorship has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def authorship(
            self,
            n: int | None = None,
            *,
            min_chars: int = 0,
    Severity: Minor
    Found in pywikibot/page/_toolforge.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 editEntity has a Cognitive Complexity of 16 (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 _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.
      
      
      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 _get_page_mappings has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
      Open

          def _get_page_mappings(self) -> None:
              """Associate label and number for each page linked to the index."""
              # Clean cache, if any.
              self._page_from_numbers = {}
              self._numbers_from_page: dict[pywikibot.page.Page, int] = {}
      Severity: Minor
      Found in pywikibot/proofreadpage.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_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

      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 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
        Severity
        Category
        Status
        Source
        Language