jenkins-bot submitted this change.
[cleanup] Remove unreachable line in solve_disambiguation.py
Unreacheble line exists for more than 15 years;
It can be removed then.
Bug: T155337
Change-Id: Idf92aa58f817b8c8f65404242919ee99476aa52e
---
M scripts/solve_disambiguation.py
1 file changed, 76 insertions(+), 57 deletions(-)
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index ff428db..4cdc94a 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -822,9 +822,10 @@
if n == 0:
# No changes necessary for this disambiguation title.
return 'nochange'
- else:
- # stop loop and save page
- break
+
+ # stop loop and save page
+ break
+
# Ensure that next time around we will not find this same hit.
curpos = m.start() + 1
try:
@@ -833,21 +834,27 @@
foundlink.parse()
except pywikibot.Error:
continue
+
# ignore interwiki links
if foundlink.site != disambPage.site:
continue
+
# Check whether the link found is to disambPage.
try:
if foundlink.canonical_title() != disambPage.title():
continue
+
except pywikibot.Error:
# must be a broken link
pywikibot.log('Invalid link [[%s]] in page [[%s]]'
% (m.group('title'), refPage.title()))
continue
+
n += 1
+
# how many bytes should be displayed around the current link
context = 60
+
# check if there's a dn-template here already
if (self.dnSkip and self.dn_template_str
and self.dn_template_str[:-2] in text[
@@ -868,6 +875,7 @@
StandardOption('next page', 'n'),
StandardOption('next disambig', 'g'),
StandardOption('unlink', 'u')]
+
if self.dn_template_str:
# '?', '/' for old choice
options += [AliasOption('tag template %s' %
@@ -877,6 +885,7 @@
if not edited:
options += [ShowPageOption('show disambiguation page', 'd',
m.start(), disambPage)]
+
options += [
OutputProxyOption('list', 'l',
SequenceOutputter(self.alternatives)),
@@ -892,22 +901,26 @@
if answer == 'x':
assert edited, 'invalid option before editing'
break
- elif answer == 's':
+
+ if answer == 's':
n -= 1 # TODO what's this for?
continue
- elif answer == 'e':
+
+ if answer == 'e':
text = edit.new_text
edited = True
curpos = 0
continue
- elif answer == 'n':
+
+ if answer == 'n':
# skip this page
if self.primary:
# If run with the -primary argument, skip this
# occurrence next time.
self.primaryIgnoreManager.ignore(refPage)
return 'nextpage'
- elif answer == 'g':
+
+ if answer == 'g':
return 'nextdisambig'
# The link looks like this:
@@ -918,13 +931,16 @@
if not link_text:
# or like this: [[page_title]]trailing_chars
link_text = page_title
+
if m.group('section') is None:
section = ''
else:
section = m.group('section')
+
trailing_chars = m.group('linktrail')
if trailing_chars:
link_text += trailing_chars
+
if answer == 't':
assert self.dn_template_str
# small chunk of text to search
@@ -932,71 +948,73 @@
# figure out where the link (and sentence) ends, put note
# there
end_of_word_match = re.search(r'\s', search_text)
+
if end_of_word_match:
position_split = end_of_word_match.start(0)
else:
position_split = 0
+
# insert dab needed template
text = (text[:m.end() + position_split]
+ self.dn_template_str
+ text[m.end() + position_split:])
dn = True
continue
- elif answer == 'u':
+
+ if answer == 'u':
# unlink - we remove the section if there's any
text = text[:m.start()] + link_text + text[m.end():]
unlink_counter += 1
continue
- else:
- # Check that no option from above was missed
- assert isinstance(answer, tuple), 'only tuple answer left.'
- assert answer[0] in ['r', ''], 'only valid tuple answers.'
- if answer[0] == 'r':
- # we want to throw away the original link text
- replaceit = link_text == page_title
- elif include == 'redirect':
- replaceit = True
- else:
- replaceit = False
- new_page_title = answer[1]
- repPl = pywikibot.Page(pywikibot.Link(new_page_title,
- disambPage.site))
- if (new_page_title[0].isupper()
- or link_text[0].isupper()):
- new_page_title = repPl.title()
- else:
- new_page_title = repPl.title()
- new_page_title = first_lower(new_page_title)
- if new_page_title not in new_targets:
- new_targets.append(new_page_title)
- if replaceit and trailing_chars:
- newlink = '[[{0}{1}]]{2}'.format(new_page_title,
- section,
- trailing_chars)
- elif replaceit or (new_page_title == link_text
- and not section):
- newlink = '[[{0}]]'.format(new_page_title)
- # check if we can create a link with trailing characters
- # instead of a pipelink
- elif (
- (len(new_page_title) <= len(link_text))
- and (firstcap(link_text[:len(new_page_title)])
- == firstcap(new_page_title))
- and (self.trailR.sub(
- '', link_text[len(new_page_title):]) == '')
- and (not section)
- ):
- newlink = '[[{0}]]{1}'.format(
- link_text[:len(new_page_title)],
- link_text[len(new_page_title):])
- else:
- newlink = '[[{0}{1}|{2}]]'.format(new_page_title,
- section, link_text)
- text = text[:m.start()] + newlink + text[m.end():]
- continue
- # Todo: This line is unreachable (T155337)
- pywikibot.output(text[max(0, m.start() - 30):m.end() + 30])
+ # else check that no option from above was missed
+ assert isinstance(answer, tuple), 'only tuple answer left.'
+ assert answer[0] in ['r', ''], 'only valid tuple answers.'
+
+ if answer[0] == 'r':
+ # we want to throw away the original link text
+ replaceit = link_text == page_title
+ else:
+ replaceit = include == 'redirect'
+
+ new_page_title = answer[1]
+ repPl = pywikibot.Page(pywikibot.Link(new_page_title,
+ disambPage.site))
+ if new_page_title[0].isupper() or link_text[0].isupper():
+ new_page_title = repPl.title()
+ else:
+ new_page_title = repPl.title()
+ new_page_title = first_lower(new_page_title)
+
+ if new_page_title not in new_targets:
+ new_targets.append(new_page_title)
+
+ if replaceit and trailing_chars:
+ newlink = '[[{0}{1}]]{2}'.format(new_page_title,
+ section,
+ trailing_chars)
+ elif replaceit or (new_page_title == link_text
+ and not section):
+ newlink = '[[{0}]]'.format(new_page_title)
+ # check if we can create a link with trailing characters
+ # instead of a pipelink
+ elif (
+ (len(new_page_title) <= len(link_text))
+ and (firstcap(link_text[:len(new_page_title)])
+ == firstcap(new_page_title))
+ and (self.trailR.sub(
+ '', link_text[len(new_page_title):]) == '')
+ and (not section)
+ ):
+ newlink = '[[{0}]]{1}'.format(
+ link_text[:len(new_page_title)],
+ link_text[len(new_page_title):])
+ else:
+ newlink = '[[{0}{1}|{2}]]'.format(new_page_title,
+ section, link_text)
+ text = text[:m.start()] + newlink + text[m.end():]
+ continue
+
if text == original_text:
pywikibot.output('\nNo changes have been made:\n')
else:
@@ -1012,6 +1030,7 @@
pywikibot.output('Page not saved: page is locked')
except pywikibot.PageNotSaved as error:
pywikibot.output('Page not saved: {0}'.format(error.args))
+
return 'done'
def findAlternatives(self, disambPage) -> bool:
To view, visit change 638071. To unsubscribe, or for help writing mail filters, visit settings.