pywikibot/site/_upload.py
Function _upload
has a Cognitive Complexity of 140 (exceeds 10 allowed). Consider refactoring. Open
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
- Read upRead up
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
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
- Read upRead up
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
Open
def __init__(self,
Avoid deeply nested control flow statements. Open
Open
if poll:
# run a poll; not possible in first iteration
assert file_key
req = self.site.simple_request(
action='upload',
Avoid deeply nested control flow statements. Open
Open
if error.code == 'stashfailed' \
and 'offset' in error.other:
# TODO: Ask MediaWiki to change this
# ambiguous error code.
Avoid deeply nested control flow statements. Open
Open
if 'nochange' in data: # in simulation mode
break
# Polls may not contain file key in response
file_key = data.get('filekey', file_key)
Avoid deeply nested control flow statements. Open
Open
if data['result'] == 'Warning':
assert ('warnings' in data
and not ignore_all_warnings)
if callable(ignore_warnings):
restart = False
Avoid deeply nested control flow statements. Open
Open
if data['result'] == 'Continue':
throttle = False
if 'offset' in data:
new_offset = int(data['offset'])
if offset + len(chunk) != new_offset:
TODO found Open
Open
# TODO: Use sessionkey instead of filekey if necessary
- Exclude checks
TODO found Open
Open
# TODO: Dummy value to allow also Unicode names, see bug T75661
- Exclude checks
TODO found Open
Open
# TODO: Ask MediaWiki to change this
- Exclude checks
hack found Open
Open
# workaround (hack) for T132676
- Exclude checks
TODO found Open
Open
# TODO: Probably needs to be reflected in the API call
- Exclude checks
TODO found Open
Open
# TODO: catch and process foreseeable errors
- Exclude checks