Xqt submitted this change.

View Change

Approvals: Xqt: Verified; Looks good to me, approved
[IMPR] solve some linter issues

- fix spelling mistake in Timestamp
- raise a ValueError if a ts parameter of Timestamp is not a supported type
- use chained comparison
- hide unused variable in test_set_from_string_invalid for loop
- use context manager with assertRaisesRegex
- make HarvestRobot.handle_string() a staticmethod

Change-Id: I3687a146600229ff80318228bf9e516d479e5725
---
M pywikibot/time.py
M scripts/harvest_template.py
M tests/time_tests.py
3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/pywikibot/time.py b/pywikibot/time.py
index ed5f00e..9ff20a9 100644
--- a/pywikibot/time.py
+++ b/pywikibot/time.py
@@ -82,7 +82,7 @@

:param ts: Timestamp, datetime.datetime or str
:return: Timestamp object
- :raises ValuError: conversion failed
+ :raises ValueError: conversion failed
"""
if isinstance(ts, cls):
return ts
@@ -90,6 +90,8 @@
return cls._from_datetime(ts)
if isinstance(ts, str):
return cls._from_string(ts)
+ raise ValueError('Unsupported "ts" type, got "{}" ({})'
+ .format(ts, type(ts).__name__))

@staticmethod
def _from_datetime(dt: datetime.datetime) -> 'Timestamp':
@@ -170,7 +172,7 @@
sec = int(m.group('S'))
usec = m.group('u')
usec = int(usec.ljust(6, '0')) if usec else 0
- if sec < 0 and usec > 0:
+ if sec < 0 < usec:
sec = sec - 1
usec = 1000000 - usec

diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index be5a471..6bb3ef0 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -118,7 +118,7 @@
willstop = False


-def _signal_handler(signal, frame) -> None:
+def _signal_handler(signum, frame) -> None:
global willstop
if not willstop:
willstop = True
@@ -394,7 +394,8 @@
if linked_item:
yield linked_item

- def handle_string(self, value, *args) -> Iterator[str]:
+ @staticmethod
+ def handle_string(value, *args) -> Iterator[str]:
"""Handle 'string' and 'external-id' claim type.

.. versionadded:: 7.4
diff --git a/tests/time_tests.py b/tests/time_tests.py
index 585f039..1247228 100755
--- a/tests/time_tests.py
+++ b/tests/time_tests.py
@@ -81,7 +81,7 @@
"""Compute POSIX timestamp with independent method."""
sec, usec = map(int, timestr.split('.'))

- if sec < 0 and usec > 0:
+ if sec < 0 < usec:
sec = sec - 1
usec = 1000000 - usec

@@ -109,11 +109,11 @@

def test_set_from_string_invalid(self):
"""Test failure creating instance from invalid string."""
- for timestr, posix in self.test_results['INVALID']:
+ for timestr, _posix in self.test_results['INVALID']:
regex = "time data \'[^\']*?\' does not match"
- with self.subTest(timestr):
- self.assertRaisesRegex(ValueError, regex,
- Timestamp.set_timestamp, timestr)
+ with self.subTest(timestr), \
+ self.assertRaisesRegex(ValueError, regex):
+ Timestamp.set_timestamp(timestr)

def test_clone(self):
"""Test cloning a Timestamp instance."""

To view, visit change 811340. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3687a146600229ff80318228bf9e516d479e5725
Gerrit-Change-Number: 811340
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged