jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/991966 )
Change subject: [flake8] solve flake8-raise issues ......................................................................
[flake8] solve flake8-raise issues
Change-Id: I9ffd7cbf0074485873c0bef100e4b0f5feb8d239 --- M pywikibot/bot_choice.py M pywikibot/page/_user.py M pywikibot/site/_apisite.py M pywikibot/site/_upload.py M pywikibot/site_detect.py M pywikibot/userinterfaces/terminal_interface_win32.py M setup.py M tests/api_tests.py M tests/ui_options_tests.py M tox.ini 10 files changed, 30 insertions(+), 19 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py index cc79ef8..5ece69f 100644 --- a/pywikibot/bot_choice.py +++ b/pywikibot/bot_choice.py @@ -1,6 +1,6 @@ """Options and Choices for :py:meth:`pywikibot.input_choice`.""" # -# (C) Pywikibot team, 2015-2022 +# (C) Pywikibot team, 2015-2024 # # Distributed under the terms of the MIT license. # @@ -79,11 +79,11 @@
def format(self, default: str | None = None) -> str: """Return a formatted string for that option.""" - raise NotImplementedError() + raise NotImplementedError
def test(self, value: str) -> bool: """Return True whether this option applies.""" - raise NotImplementedError() + raise NotImplementedError
@abstractmethod def result(self, value: str) -> Any: @@ -93,7 +93,7 @@ *result()* is an abstract method and must be defined in subclasses """ - raise NotImplementedError() + raise NotImplementedError
class OutputOption(Option): @@ -273,7 +273,7 @@ @abstractmethod def handle(self) -> Any: """Handle this choice. Must be implemented.""" - raise NotImplementedError() + raise NotImplementedError
def handle_link(self) -> bool: """The current link will be handled by this choice.""" diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py index 2aee039..0df8acc 100644 --- a/pywikibot/page/_user.py +++ b/pywikibot/page/_user.py @@ -278,7 +278,7 @@ if err.code == 'invalidrange': raise ValueError(f'{self.username} is not a valid IP range.')
- raise err + raise
def unblock(self, reason: str | None = None) -> None: """ diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py index 37bbc8e..e134607 100644 --- a/pywikibot/site/_apisite.py +++ b/pywikibot/site/_apisite.py @@ -403,9 +403,9 @@ # May occur if you are not logged in (no API read permissions). except APIError: pass - except NoUsernameError as e: + except NoUsernameError: if not autocreate: - raise e + raise
if self.is_oauth_token_available(): if self.userinfo['name'] == self.username(): diff --git a/pywikibot/site/_upload.py b/pywikibot/site/_upload.py index f40e2ab..7adc5fc 100644 --- a/pywikibot/site/_upload.py +++ b/pywikibot/site/_upload.py @@ -1,6 +1,6 @@ """Objects representing API upload to MediaWiki site.""" # -# (C) Pywikibot team, 2009-2023 +# (C) Pywikibot team, 2009-2024 # # Distributed under the terms of the MIT license. # @@ -347,7 +347,7 @@ 'offset mismatch error.') offset = new_offset continue - raise error + raise if 'nochange' in data: # in simulation mode break
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index 7567a6f..5d3a61c 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -1,6 +1,6 @@ """Classes for detecting a MediaWiki site.""" # -# (C) Pywikibot team, 2010-2023 +# (C) Pywikibot team, 2010-2024 # # Distributed under the terms of the MIT license. # @@ -300,7 +300,7 @@ except ValueError as err: m = re.search(r'\d{3}', err.args[0], flags=re.ASCII) if not m: - raise err + raise msg = f'Generic {err_type} Error ({m.group()})' else: msg = f'({status}) {status.description}' diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py index c2039e2..604fb6b 100644 --- a/pywikibot/userinterfaces/terminal_interface_win32.py +++ b/pywikibot/userinterfaces/terminal_interface_win32.py @@ -1,6 +1,6 @@ """User interface for Win32 terminals.""" # -# (C) Pywikibot team, 2003-2022 +# (C) Pywikibot team, 2003-2024 # # Distributed under the terms of the MIT license. # @@ -67,5 +67,5 @@ def _raw_input(self): # pragma: no cover data = self.stdin.readline() if '\x1a' in data: - raise EOFError() + raise EOFError return data.strip() diff --git a/setup.py b/setup.py index 0275e71..fd8bd4b 100755 --- a/setup.py +++ b/setup.py @@ -64,6 +64,7 @@ 'flake8-mock-x2', 'flake8-print>=5.0.0', 'flake8-quotes>=3.3.2', + 'flake8-raise', 'flake8-string-format', 'flake8-tuple>=0.4.1', 'flake8-no-u-prefixed-strings>=0.2', diff --git a/tests/api_tests.py b/tests/api_tests.py index 1575274..8f4eb41 100755 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """API test module.""" # -# (C) Pywikibot team, 2007-2023 +# (C) Pywikibot team, 2007-2024 # # Distributed under the terms of the MIT license. # @@ -939,10 +939,10 @@ req.submit() except SystemExit: pass # expected exception from DummyThrottle instance - except APIError as e: # pragma: no cover + except APIError: # pragma: no cover pywikibot.warning( 'Wrong api lagpattern regex, cannot retrieve lag value') - raise e + raise self.assertIsInstance(mythrottle._lagvalue, (int, float)) self.assertGreaterEqual(mythrottle._lagvalue, 0) self.assertIsInstance(mythrottle.retry_after, int) diff --git a/tests/ui_options_tests.py b/tests/ui_options_tests.py index e05efa2..701f359 100755 --- a/tests/ui_options_tests.py +++ b/tests/ui_options_tests.py @@ -212,7 +212,7 @@ self.assertEqual(option.option, 'quit') self.assertEqual(option.shortcut, 'q') with self.assertRaises(QuitKeyboardInterrupt): - raise QuitKeyboardInterrupt() + raise QuitKeyboardInterrupt
if __name__ == '__main__': # pragma: no cover diff --git a/tox.ini b/tox.ini index fe8b050..d7de29f 100644 --- a/tox.ini +++ b/tox.ini @@ -128,6 +128,7 @@ # P101: format string does contain unindexed parameters # P102: docstring does contain unindexed parameters # P103: other string does contain unindexed parameters +# R100: raise in except handler without from # W503: line break before binary operator; against current PEP 8 recommendation
# Errors occurred after upgrade to pydocstyle 2.0.0 (T164142) @@ -137,7 +138,7 @@
# DARXXX: Darglint docstring issues to be solved
-ignore = B007,D105,D211,D401,D413,D412,DAR003,DAR101,DAR102,DAR201,DAR202,DAR301,DAR401,DAR402,DAR501,H101,H238,H301,H306,H404,H405,H903,P101,P102,P103,P205,W503 +ignore = B007,D105,D211,D401,D413,D412,DAR003,DAR101,DAR102,DAR201,DAR202,DAR301,DAR401,DAR402,DAR501,H101,H238,H301,H306,H404,H405,H903,P101,P102,P103,P205,R100,W503 enable-extensions = H203,H204,H205,N818
count = True
pywikibot-commits@lists.wikimedia.org