wikimedia/pywikibot

View on GitHub
pywikibot/site/_upload.py

Summary

Maintainability
F
4 days
Test Coverage

Function _upload has a Cognitive Complexity of 140 (exceeds 10 allowed). Consider refactoring.
Open

    def _upload(self, ignore_warnings, report_success,
                file_key=None, offset=0) -> bool:
        """Recursive Upload method.

        :param file_key: Reuses an already uploaded file using the
Severity: Minor
Found in pywikibot/site/_upload.py - About 2 days 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

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

    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

      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 'nochange' in data:  # in simulation mode
                                    break
        
                                # Polls may not contain file key in response
                                file_key = data.get('filekey', file_key)
        Severity: Major
        Found in pywikibot/site/_upload.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if data['result'] == 'Warning':
                                      assert ('warnings' in data
                                              and not ignore_all_warnings)
                                      if callable(ignore_warnings):
                                          restart = False
          Severity: Major
          Found in pywikibot/site/_upload.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if data['result'] == 'Continue':
                                        throttle = False
                                        if 'offset' in data:
                                            new_offset = int(data['offset'])
                                            if offset + len(chunk) != new_offset:
            Severity: Major
            Found in pywikibot/site/_upload.py - About 45 mins to fix

              TODO found
              Open

                          # TODO: Use sessionkey instead of filekey if necessary
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              TODO found
              Open

                          # TODO: Dummy value to allow also Unicode names, see bug T75661
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              TODO found
              Open

                                              # TODO: Ask MediaWiki to change this
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              hack found
              Open

                                          # workaround (hack) for T132676
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              TODO found
              Open

                                      # TODO: Probably needs to be reflected in the API call
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              TODO found
              Open

                                          # TODO: catch and process foreseeable errors
              Severity: Minor
              Found in pywikibot/site/_upload.py by fixme

              There are no issues that match your filters.

              Category
              Status