wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

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

        ts1 = pywikibot.Timestamp(
            year=2023, month=12, day=21, hour=13,
            tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
Severity: Major
Found in tests/wbtypes_tests.py and 4 other locations - About 45 mins to fix
tests/wbtypes_tests.py on lines 414..416
tests/wbtypes_tests.py on lines 484..486
tests/wbtypes_tests.py on lines 499..501
tests/wbtypes_tests.py on lines 532..534

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

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

Avoid deeply nested control flow statements.
Open

                        if hunk.reviewed == Hunk.PENDING:
                            hunk.reviewed = \
                                Hunk.APPR if choice == 'a' else Hunk.NOT_APPR
                position = find_pending(0, position)
Severity: Major
Found in pywikibot/diff.py - About 45 mins to fix

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

        def preloadpages(
    Severity: Major
    Found in pywikibot/site/_generators.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if family == 'wiki':
                                  family = 'wikipedia'
                              return pywikibot.Site(code, family)
      Severity: Major
      Found in pywikibot/site/_apisite.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                    if 'offset' in data:
                                        new_offset = int(data['offset'])
                                        if offset + len(chunk) != new_offset:
                                            pywikibot.log(
                                                f'Old offset: {offset}; Returned '
        Severity: Major
        Found in pywikibot/site/_upload.py - About 45 mins to fix

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

              def pagereferences(
          Severity: Major
          Found in pywikibot/site/_generators.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                with open(include) as g:
                                    desc.append(re.sub(pattern[0], pattern[1], g.read()))
                            else:  # pragma: no cover
            Severity: Major
            Found in setup.py - About 45 mins to fix

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

              def replaceExcept(text: str,
              Severity: Major
              Found in pywikibot/textlib.py - About 45 mins to fix

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

                        ts1 = pywikibot.Timestamp(
                            year=2023, month=12, day=21, hour=13,
                            tzinfo=datetime.timezone(datetime.timedelta(hours=-5)))
                Severity: Major
                Found in tests/wbtypes_tests.py and 4 other locations - About 45 mins to fix
                tests/wbtypes_tests.py on lines 414..416
                tests/wbtypes_tests.py on lines 484..486
                tests/wbtypes_tests.py on lines 523..525
                tests/wbtypes_tests.py on lines 532..534

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

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

                    def addDirectedEdge(self, page: pywikibot.page.Page,
                                        refPage: pywikibot.page.Page) -> None:
                        """Add a directed edge from refPage to page."""
                        assert self.graph is not None
                        # if page was given as a hint, referrers would be [None]
                Severity: Minor
                Found in pywikibot/interwiki_graph.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

                Consider simplifying this complex logical expression.
                Open

                        if '.' in t and (t in ('.', '..')
                                         or t.startswith(('./', '../'))
                                         or '/./' in t
                                         or '/../' in t
                                         or t.endswith(('/.', '/..'))):
                Severity: Major
                Found in pywikibot/page/_links.py - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if arg == 'noauto':
                              self.auto = False
                          elif arg == 'hint':
                              self.hints.append(value)
                          elif arg == 'hintfile':
                  Severity: Major
                  Found in scripts/interwiki.py - About 40 mins to fix

                    Consider simplifying this complex logical expression.
                    Open

                                if new_page_title == link_text and not section \
                                   or self.opt.overwrite:
                                    newlink = f'[[{new_page_title}]]'
                                # check if we can create a link with trailing characters instead of
                                # a pipelink
                    Severity: Major
                    Found in scripts/fixing_redirects.py - About 40 mins to fix

                      Consider simplifying this complex logical expression.
                      Open

                              if opt == 'start':
                                  options[opt] = value or pywikibot.input(
                                      'From which title do you want to continue?')
                              elif opt == 'save':
                                  options[opt] = value or pywikibot.input(
                      Severity: Major
                      Found in scripts/parser_function_count.py - About 40 mins to fix

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

                                with self.assertRaisesRegex(
                                        ValidationError,
                                        f'{self.ISBN_DIGITERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
                                        f'{self.ISBN_INVALIDLENGTHERROR_RE}'
                                ):
                        Severity: Major
                        Found in tests/cosmetic_changes_tests.py and 2 other locations - About 40 mins to fix
                        tests/cosmetic_changes_tests.py on lines 597..602
                        tests/cosmetic_changes_tests.py on lines 604..609

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

                        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

                                with self.assertRaisesRegex(
                                    ValidationError,
                                    f'{self.ISBN_INVALIDCHARERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
                                    f'{self.ISBN_INVALIDLENGTHERROR_RE}'
                                ):
                        Severity: Major
                        Found in tests/cosmetic_changes_tests.py and 2 other locations - About 40 mins to fix
                        tests/cosmetic_changes_tests.py on lines 582..587
                        tests/cosmetic_changes_tests.py on lines 597..602

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

                        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

                                with self.assertRaisesRegex(
                                        ValidationError,
                                        f'{self.ISBN_DIGITERROR_RE}|{self.ISBN_INVALIDERROR_RE}|'
                                        f'{self.ISBN_INVALIDLENGTHERROR_RE}'
                                ):
                        Severity: Major
                        Found in tests/cosmetic_changes_tests.py and 2 other locations - About 40 mins to fix
                        tests/cosmetic_changes_tests.py on lines 582..587
                        tests/cosmetic_changes_tests.py on lines 604..609

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

                        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 change_category has 8 arguments (exceeds 7 allowed). Consider refactoring.
                        Open

                            def change_category(self, old_cat, new_cat,
                        Severity: Major
                        Found in pywikibot/page/_basepage.py - About 35 mins to fix

                          Function getReferences has 8 arguments (exceeds 7 allowed). Consider refactoring.
                          Open

                              def getReferences(self,
                          Severity: Major
                          Found in pywikibot/page/_basepage.py - About 35 mins to fix

                            Function download has 8 arguments (exceeds 7 allowed). Consider refactoring.
                            Open

                                def download(self,
                            Severity: Major
                            Found in pywikibot/page/_filepage.py - About 35 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language