jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/770317 )

Change subject: cleanup/remove blanket noqa and type: ignore
......................................................................

cleanup/remove blanket noqa and type: ignore

Change-Id: I728083d5a35a6d236c8df3cdefd07b2772483dd7
---
M pywikibot/bot.py
M pywikibot/date.py
M pywikibot/families/wikibooks_family.py
M pywikibot/families/wikinews_family.py
M pywikibot/families/wikiquote_family.py
M pywikibot/families/wikisource_family.py
M pywikibot/families/wiktionary_family.py
M pywikibot/logging.py
M pywikibot/pagegenerators.py
M scripts/category.py
M scripts/commonscat.py
M scripts/watchlist.py
12 files changed, 47 insertions(+), 40 deletions(-)

Approvals:
  JJMC89: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index ec2d322..e9106ba 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -994,11 +994,12 @@
         try:
             main = sys.modules['__main__'].main  # type: ignore[attr-defined]
             module_name = main.__module__
+            assert module_name is not None
         except NameError:
             module_name = 'no_module'

     try:
-        module = import_module(module_name)  # type: ignore
+        module = import_module(module_name)
         help_text = module.__doc__  # type: str # type: ignore[assignment]
         if hasattr(module, 'docuReplacements'):
             for key, value in module.docuReplacements.items():
diff --git a/pywikibot/date.py b/pywikibot/date.py
index a18f160..17f5563 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -234,7 +234,7 @@
     return lst[value - 1]


[email protected](str)  # type: ignore
[email protected](str)
 def _(value: str, lst: Sequence[str]) -> int:
     return lst.index(value) + 1

@@ -245,7 +245,7 @@
     return dh_constVal(value, 0, match)


-@dh_singVal.register(str)  # type: ignore
+@dh_singVal.register(str)
 def _(value: str, match: str) -> int:
     return dh_constVal(value, 0, match)  # type: ignore[return-value]

@@ -262,7 +262,7 @@
     raise ValueError('unknown value {}'.format(value))


-@dh_constVal.register(str)  # type: ignore
+@dh_constVal.register(str)
 def _(value: str, ind: int, match: str) -> int:
     if value == match:
         return ind
@@ -351,7 +351,7 @@
 # (from int to a str) and decoder (from str to an int)
 _digitDecoders = {
     # %% is a %
-    '%': '%',  # type: ignore
+    '%': '%',
     # %d is a decimal
     'd': (_decimalDigits, str, int),
     # %R is a roman numeral. This allows for only the simplest linear
@@ -409,7 +409,7 @@
             newpattern += '([{}]{{{}}})'.format(dec[0], subpattern[1])
             # add the number of required digits as the last (4th)
             # part of the tuple
-            decoders.append(dec + (int(s[1]),))  # type: ignore
+            decoders.append(dec + (int(s[1]),))
         else:
             newpattern += '([{}]+)'.format(dec[0])
             decoders.append(dec)
@@ -507,7 +507,7 @@
     return strPattern % _make_parameter(decoders[0], params)


[email protected](str)  # type: ignore
[email protected](str)
 def _(value: str, pattern: str, encf: encf_type, decf: decf_type,
       filter: Optional[Callable[[int], bool]] = None) -> int:
     compPattern, _strPattern, decoders = escapePattern2(pattern)
@@ -531,7 +531,7 @@

 def _make_parameter(decoder: decoder_type, param: int) -> str:
     newValue = decoder[1](param)
-    required_digits = decoder[3] if len(decoder) == 4 else None  # type: ignore
+    required_digits = decoder[3] if len(decoder) == 4 else None
     if required_digits is not None and len(newValue) < required_digits:
         # force parameter length by taking the first digit in the list and
         # repeating it required number of times
@@ -552,7 +552,7 @@
 # This is useful when trying to decide if a certain article is a localized date
 # or not, or generating dates.
 # See dh() for additional information.
-class MonthNames(abc.Mapping):
+class MonthNames(Mapping):

     """A Mapping which reads month names from MediaWiki messages."""

@@ -682,7 +682,7 @@
             elif ucase is False:
                 f = first_lower
             else:
-                f = str  # type: ignore
+                f = str

             month_pattern = pattern.format(f(monthName(key, self.index)))
             expression = "lambda v: {}(v, '{}')".format(func, month_pattern)
@@ -1674,18 +1674,18 @@
         'yo': lambda v: dh_singVal(v, 'Current events'),
         'zh': lambda v: dh_singVal(v, '新闻动态'),
     },
-}  # type: Dict[str, Dict[str, Callable[[int], str]]]
+}  # type: Dict[Union[str, int], Mapping[str, Callable[[int], str]]]

-formats['MonthName'] = MonthNames()  # type: ignore[assignment]
+formats['MonthName'] = MonthNames()
 #
 # Add auto-generated empty dictionaries for DayOfMonth and MonthOfYear articles
 #
 for index, day_of_month in enumerate(dayMnthFmts, 1):
     val = MonthFormat(index, day_of_month)
-    formats[day_of_month] = val  # type: ignore[assignment]
+    formats[day_of_month] = val
 for index, month_of_year in enumerate(yrMnthFmts, 1):
     val = MonthFormat(index, month_of_year)
-    formats[month_of_year] = val  # type: ignore[assignment]
+    formats[month_of_year] = val


 def addFmt1(lang: str, isMnthOfYear: bool,
@@ -1981,7 +1981,7 @@
     """
     for dict_name, dictionary in formats.items():
         with suppress(Exception):
-            year = dictionary[lang](title)  # type: ignore
+            year = dictionary[lang](title)
             return dict_name, year
     # sometimes the title may begin with an upper case while its listed as
     # lower case, or the other way around
diff --git a/pywikibot/families/wikibooks_family.py 
b/pywikibot/families/wikibooks_family.py
index 8374f59..ff2ec99 100644
--- a/pywikibot/families/wikibooks_family.py
+++ b/pywikibot/families/wikibooks_family.py
@@ -15,7 +15,7 @@
     name = 'wikibooks'

     closed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # 
noqa: E501
         'aa', 'ak', 'ang', 'as', 'ast', 'ay', 'bi', 'bm', 'bo', 'ch', 'co',
         'ga', 'gn', 'got', 'gu', 'ie', 'kn', 'ks', 'lb', 'ln', 'lv', 'mi',
         'mn', 'my', 'na', 'nah', 'nds', 'ps', 'qu', 'rm', 'se', 'simple', 'su',
@@ -24,7 +24,7 @@
     ]

     removed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # 
noqa: E501
         'als', 'dk', 'tokipona',
     ]

diff --git a/pywikibot/families/wikinews_family.py 
b/pywikibot/families/wikinews_family.py
index 9049113..e070e81 100644
--- a/pywikibot/families/wikinews_family.py
+++ b/pywikibot/families/wikinews_family.py
@@ -15,7 +15,7 @@
     name = 'wikinews'

     closed_wikis = [
-        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # noqa
+        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # 
noqa: E501
         'bg', 'hu', 'sd', 'th', 'tr',
     ]

diff --git a/pywikibot/families/wikiquote_family.py 
b/pywikibot/families/wikiquote_family.py
index 721ad44..d9a8ff8 100644
--- a/pywikibot/families/wikiquote_family.py
+++ b/pywikibot/families/wikiquote_family.py
@@ -15,14 +15,14 @@
     name = 'wikiquote'

     closed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # 
noqa: E501
         'am', 'ang', 'ast', 'bm', 'co', 'cr', 'ga', 'kk', 'kr', 'ks', 'kw',
         'lb', 'na', 'nds', 'qu', 'simple', 'tk', 'tt', 'ug', 'vo', 'za',
         'zh-min-nan',
     ]

     removed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # 
noqa: E501
         'als', 'tokipona',
     ]

diff --git a/pywikibot/families/wikisource_family.py 
b/pywikibot/families/wikisource_family.py
index 6dd6ba3..7fc3000 100644
--- a/pywikibot/families/wikisource_family.py
+++ b/pywikibot/families/wikisource_family.py
@@ -16,11 +16,11 @@
     name = 'wikisource'

     closed_wikis = [
-        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # noqa
+        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # 
noqa: E501
         'ang', 'ht',
     ]
     removed_wikis = [
-        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # noqa
+        # 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # 
noqa: E501
         'tokipona',
     ]

diff --git a/pywikibot/families/wiktionary_family.py 
b/pywikibot/families/wiktionary_family.py
index 8980173..f9c55ab 100644
--- a/pywikibot/families/wiktionary_family.py
+++ b/pywikibot/families/wiktionary_family.py
@@ -16,13 +16,13 @@
     name = 'wiktionary'

     closed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/closed.dblist  # 
noqa: E501
         'aa', 'ab', 'ak', 'as', 'av', 'bh', 'bi', 'bm', 'bo', 'ch', 'cr', 'dz',
         'ik', 'mh', 'pi', 'rm', 'rn', 'sc', 'sn', 'to', 'tw', 'xh', 'yo', 'za',
     ]

     removed_wikis = [
-        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # noqa
+        # See 
https://noc.wikimedia.org/conf/highlight.php?file=dblists/deleted.dblist  # 
noqa: E501
         'als', 'ba', 'dk', 'tlh', 'tokipona',
     ]

diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index 63c17a9..c6db03d 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -30,14 +30,14 @@

 # logging levels
 from logging import CRITICAL, DEBUG, ERROR, INFO, WARNING
-from typing import Any, Optional
+from typing import Any, Optional, Union

 from pywikibot.backports import Callable, List


-STDOUT = 16  #:
-VERBOSE = 18  #:
-INPUT = 25  #:
+STDOUT = 16
+VERBOSE = 18
+INPUT = 25

 _init_routines = []  # type: List[Callable[[], Any]]
 _inited_routines = set()
@@ -221,8 +221,13 @@
     logoutput(text, decoder, newline, DEBUG, layer, **kwargs)


-def exception(msg: Optional[Exception] = None, decoder: Optional[str] = None,
-              newline: bool = True, tb: bool = False, **kwargs: Any) -> None:
+def exception(
+    msg: Union[Exception, str, None] = None,
+    decoder: Optional[str] = None,
+    newline: bool = True,
+    tb: bool = False,
+    **kwargs: Any
+) -> None:
     """Output an error traceback to the user via the userinterface.

     Use directly after an 'except' statement::
@@ -251,12 +256,13 @@
     :param tb: Set to True in order to output traceback also.
     """
     if isinstance(msg, BaseException):
-        exc_info = 1  # type: Any
+        if tb:
+            kwargs['exc_info'] = 1
     else:
         exc_info = sys.exc_info()
-        msg = '{}: {}'.format(repr(exc_info[1]).split('(')[0],  # type: ignore
+        msg = '{}: {}'.format(repr(exc_info[1]).split('(')[0],
                               str(exc_info[1]).strip())
-    if tb:
-        kwargs['exc_info'] = exc_info
+        if tb:
+            kwargs['exc_info'] = exc_info
     assert msg is not None
     logoutput(msg, decoder, newline, ERROR, **kwargs)
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 2022f22..a4f998d 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -33,7 +33,7 @@
 from typing import Any, Optional, Union
 from urllib.parse import urlparse

-from requests.exceptions import ReadTimeout  # type: ignore[import]
+from requests.exceptions import ReadTimeout

 import pywikibot
 from pywikibot import config, date, i18n, xmlreader
@@ -596,7 +596,7 @@

             if self.limit:
                 try:
-                    gen_item.set_maximum_items(self.limit)  # type: ignore
+                    gen_item.set_maximum_items(self.limit)  # type: 
ignore[attr-defined]  # noqa: E501
                 except AttributeError:
                     self.gens[i] = itertools.islice(gen_item, self.limit)

diff --git a/scripts/category.py b/scripts/category.py
index 03cd40e..f86bc79 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -612,10 +612,10 @@
         self.oldtalk = self.oldcat.toggleTalkPage()

         if newcat:
-            self.newcat = self._makecat(newcat)
+            self.newcat = self._makecat(newcat)  # type: 
Optional[pywikibot.Category]  # noqa: E501
             self.newtalk = self.newcat.toggleTalkPage()
         else:
-            self.newcat = None  # type: ignore
+            self.newcat = None
             self.newtalk = None

         # Set boolean settings.
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 1cef514..d4114e2 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -426,7 +426,7 @@
         return self.findCommonscatLink(page)

     @staticmethod
-    def getCommonscatLink(page):  # noqa N802, N803
+    def getCommonscatLink(page):  # noqa: N802
         """Find CommonsCat template on page.

         :rtype: tuple of (<templatename>, <target>, <linktext>, <note>)
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index cbb5444..8ce97e6 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -62,7 +62,7 @@
                      'for all wikis.'.format(wl_count_all))


-def isWatched(pageName, site=None):  # noqa N802, N803
+def isWatched(pageName, site=None):  # noqa: N802, N803
     """Check whether a page is being watched."""
     watchlist = get(site)
     return pageName in watchlist

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/770317
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I728083d5a35a6d236c8df3cdefd07b2772483dd7
Gerrit-Change-Number: 770317
Gerrit-PatchSet: 1
Gerrit-Owner: JJMC89 <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to