wikimedia/pywikibot

View on GitHub

Showing 616 of 616 total issues

Avoid deeply nested control flow statements.
Open

                        if key == '@metadata':
                            continue
                        self.assertTrue(
Severity: Major
Found in tests/l10n_tests.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if tu:
                                # no changes needed, better to revert the old text.
                                text = oldtext
                        else:
    Severity: Major
    Found in scripts/blockpageschecker.py - About 45 mins to fix

      Function check_image_on_commons has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
      Open

          def check_image_on_commons(self) -> bool:
              """Checking if the file is on commons."""
              pywikibot.info(f'Checking if [[{self.image_name}]] is on commons...')
              try:
                  hash_found = self.image.latest_file_info.sha1
      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

      Avoid deeply nested control flow statements.
      Open

                              if tu:
                                  # no changes needed, better to revert the old text.
                                  text = oldtext
                          else:
      Severity: Major
      Found in scripts/blockpageschecker.py - About 45 mins to fix

        Function set_redirect_target has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def set_redirect_target(
                self,
                target_page: pywikibot.Page | str,
                create: bool = False,
                force: bool = False,
        Severity: Minor
        Found in pywikibot/page/_page.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 getPDFTitle has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def getPDFTitle(ref, response) -> None:
                """Use pdfinfo to retrieve title from a PDF."""
                # pdfinfo is Unix-only
                pywikibot.info('Reading PDF file...')
                infile = None
        Severity: Minor
        Found in scripts/reflinks.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 get has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
        Open

            def get(self, force: bool = False) -> dict:
                """Fetch all MediaInfo entity data and cache it.
        
                .. note:: dicts returned by this method are references to content
                   of this entity and their modifying may indirectly cause
        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 watchlist_revs has 9 arguments (exceeds 7 allowed). Consider refactoring.
        Open

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

          Avoid deeply nested control flow statements.
          Open

                                  for qual_index, qual_statement in enumerate(qualifier):
                                      target_qual_prop = claim.qualifiers[qual_propid]
                                      target_qual = target_qual_prop[qual_index]
                                      target_qual.hash = qual_statement['hash']
                              updated_references = statement.get('references', [])
          Severity: Major
          Found in pywikibot/page/_wikibase.py - About 45 mins to fix

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

                    ts1 = pywikibot.Timestamp(
                        year=2022, 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 499..501
            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

            Avoid deeply nested control flow statements.
            Open

                                    if hunk.reviewed == Hunk.PENDING:
                                        hunk.reviewed = Hunk.NOT_APPR
                        elif choice in ['a', 'd']:
            Severity: Major
            Found in pywikibot/diff.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          if error.code == 'stashfailed' \
                                                  and 'offset' in error.other:
                                              # TODO: Ask MediaWiki to change this
                                              # ambiguous error code.
              
              
              Severity: Major
              Found in pywikibot/site/_upload.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if callable(ignore_warnings):
                                                restart = False
                                                if 'offset' not in data:
                                                    # This is a result of a warning in the
                                                    # first chunk. The chunk is not actually
                Severity: Major
                Found in pywikibot/site/_upload.py - About 45 mins to fix

                  Function merge_query_arguments has a Cognitive Complexity of 13 (exceeds 10 allowed). Consider refactoring.
                  Open

                      def merge_query_arguments(self,
                                                database_id: int | None = None,
                                                schema_name: str | None = None,
                                                site: BaseSite = None) -> tuple(int, str):
                          """Determine and validate the database_id and schema_name.
                  Severity: Minor
                  Found in pywikibot/data/superset.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

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

                          ts1 = pywikibot.Timestamp(
                              year=2022, 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 484..486
                  tests/wbtypes_tests.py on lines 499..501
                  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

                  Avoid deeply nested control flow statements.
                  Open

                                          for ref_propid, reference in ref_grp['snaks'].items():
                                              for ref_index, ref_stat in enumerate(reference):
                                                  target_ref_grp = claim.sources[ref_grp_idx]
                                                  target_ref_prop = target_ref_grp[ref_propid]
                                                  target_ref = target_ref_prop[ref_index]
                  Severity: Major
                  Found in pywikibot/page/_wikibase.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                if self.sametitle(key, pagedata['title']):
                                                    cache[pagedata['title']] = value
                                                    break
                                            else:
                    Severity: Major
                    Found in pywikibot/site/_generators.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if page.title(with_ns=False) == self._base:
                                                  what_links_here.remove(page)
                                                  self._index = (page, what_links_here)
                                                  break
                      
                      
                      Severity: Major
                      Found in pywikibot/proofreadpage.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if poll:
                                                    # run a poll; not possible in first iteration
                                                    assert file_key
                                                    req = self.site.simple_request(
                                                        action='upload',
                        Severity: Major
                        Found in pywikibot/site/_upload.py - About 45 mins to fix

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

                                  ts4 = pywikibot.Timestamp(
                                      year=2023, month=12, day=21, hour=13,
                                      tzinfo=datetime.timezone(datetime.timedelta(hours=-6)))
                          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 523..525

                          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

                          Severity
                          Category
                          Status
                          Source
                          Language