else
/elif
used after raise
PYL-R17202269 del dateDict['time']
2270
2271 # replace month name in original language with month number
2272 try:2273 value = self.origNames2monthNum[dateDict['month']['value']]
2274 except KeyError:
2275 raise KeyError(
840
841 soup = _bs4_soup(response.text) # type: ignore
842
843 try: 844 url_image = soup.find(class_='prp-page-image')
845 # if None raises AttributeError
846 url_image = url_image.find('img')
475 raise NoWikibaseEntityError(self) from exc
476 except Error as exc:
477 error_message = str(exc)
478 if 'is not a file' in error_message: 479 raise NoWikibaseEntityError(self) from exc
480 else:
481 raise Error(self) from exc
1748 :raises pywikibot.exceptions.NoMoveTargetError: page was not moved
1749 """
1750 gen = iter(self.site.logevents(logtype='move', page=self, total=1))
1751 try:1752 lastmove = next(gen)
1753 except StopIteration:
1754 raise NoMoveTargetError(self)
300
301 def change(self, text: str) -> bool | str:
302 """Execute all clean up methods and catch errors if activated."""
303 try: 304 new_text = self._change(text)
305 except Exception as e:
306 if self.ignore == CANCEL.PAGE:
raise
causes control flow to be disrupted, as it will exit the block.
It is recommended to check other conditions using another if
statement, and get rid of else
statements as they are unnecessary.
def check_magic_generator(attribute):
magic = get_magic_number(attribute)
if magic < 0:
raise ValueError(f"{attribute} looks invalid")
elif magic > 100
raise ValueError(f"{attribute} is very magical")
else:
return magic
def check_magic_generator(attribute):
magic = get_magic_number(attribute)
if magic < 0:
raise ValueError(f"{attribute} looks invalid")
if magic > 100
raise ValueError(f"{attribute} is very magical")
return magic