Merge ~cjwatson/launchpad:fix-mypy into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 3e6b74b6c6c3f7c6570e31dc9666b3933c2c03aa
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-mypy
Merge into: launchpad:master
Diff against target: 130 lines (+19/-21)
5 files modified
lib/lp/bugs/browser/bug.py (+6/-7)
lib/lp/bugs/browser/tests/test_bugs.py (+5/-2)
lib/lp/bugs/templates/malone-index.pt (+1/-1)
lib/lp/services/scripts/base.py (+3/-2)
lib/lp/translations/browser/potemplate.py (+4/-9)
Reviewer Review Type Date Requested Status
Andrey Fedoseev (community) Approve
Review via email: mp+428030@code.launchpad.net

Commit message

Fix some test failures caused by type-checking changes

Description of the change

There were three separate problems here. Full details in the individual commit messages.

To post a comment you must log in.
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) wrote :

Great, thank you for fixing that!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/browser/bug.py b/lib/lp/bugs/browser/bug.py
2index 028b4e8..3a675a8 100644
3--- a/lib/lp/bugs/browser/bug.py
4+++ b/lib/lp/bugs/browser/bug.py
5@@ -411,11 +411,6 @@ class MaloneView(LaunchpadFormView):
6
7 page_title = "Launchpad Bugs"
8
9- # Test: standalone/xx-slash-malone-slash-bugs.rst
10- @property
11- def error_message(self):
12- return None
13-
14 @property
15 def target_css_class(self):
16 """The CSS class for used in the target widget."""
17@@ -441,7 +436,9 @@ class MaloneView(LaunchpadFormView):
18 def _redirectToBug(self, bug_id):
19 """Redirect to the specified bug id."""
20 if not isinstance(bug_id, str):
21- self.error_message = "Bug %r is not registered." % bug_id
22+ self.error_message = structured(
23+ "Bug %r is not registered.", bug_id
24+ )
25 return
26 if bug_id.startswith("#"):
27 # Be nice to users and chop off leading hashes
28@@ -449,7 +446,9 @@ class MaloneView(LaunchpadFormView):
29 try:
30 bug = getUtility(IBugSet).getByNameOrID(bug_id)
31 except NotFoundError:
32- self.error_message = "Bug %r is not registered." % bug_id
33+ self.error_message = structured(
34+ "Bug %r is not registered.", bug_id
35+ )
36 else:
37 return self.request.response.redirect(canonical_url(bug))
38
39diff --git a/lib/lp/bugs/browser/tests/test_bugs.py b/lib/lp/bugs/browser/tests/test_bugs.py
40index 9801551..ecee498 100644
41--- a/lib/lp/bugs/browser/tests/test_bugs.py
42+++ b/lib/lp/bugs/browser/tests/test_bugs.py
43@@ -63,7 +63,9 @@ class TestMaloneView(TestCaseWithFactory):
44 view = create_initialized_view(
45 self.application, name="+index", form=form
46 )
47- self.assertEqual("Bug 'fnord' is not registered.", view.error_message)
48+ self.assertEqual(
49+ "Bug 'fnord' is not registered.", view.error_message.escapedtext
50+ )
51 self.assertEqual(None, view.request.response.getHeader("Location"))
52
53 def test_redirect_list_of_bug_fail(self):
54@@ -74,7 +76,8 @@ class TestMaloneView(TestCaseWithFactory):
55 self.application, name="+index", form=form
56 )
57 self.assertEqual(
58- "Bug ['fnord', 'pting'] is not registered.", view.error_message
59+ "Bug '['fnord', 'pting']' is not registered.",
60+ view.error_message.escapedtext,
61 )
62 self.assertEqual(None, view.request.response.getHeader("Location"))
63
64diff --git a/lib/lp/bugs/templates/malone-index.pt b/lib/lp/bugs/templates/malone-index.pt
65index c82e296..454aedc 100644
66--- a/lib/lp/bugs/templates/malone-index.pt
67+++ b/lib/lp/bugs/templates/malone-index.pt
68@@ -13,7 +13,7 @@
69 <div class="top-portlet">
70 <p class="error message"
71 tal:condition="view/error_message"
72- tal:content="view/error_message">
73+ tal:content="structure view/error_message/escapedtext">
74 Error message.
75 </p>
76 <form id="search-all-bugs" class="central" action="/bugs/+bugs" method="get">
77diff --git a/lib/lp/services/scripts/base.py b/lib/lp/services/scripts/base.py
78index 36d34b0..59afada 100644
79--- a/lib/lp/services/scripts/base.py
80+++ b/lib/lp/services/scripts/base.py
81@@ -19,6 +19,7 @@ from configparser import ConfigParser
82 from contextlib import contextmanager
83 from cProfile import Profile
84 from optparse import OptionParser
85+from typing import Optional
86 from urllib.parse import urlparse, urlunparse
87
88 import pytz
89@@ -137,8 +138,8 @@ class LaunchpadScript:
90
91 lock = None
92 txn = None
93- usage = ""
94- description = ""
95+ usage = None # type: Optional[str]
96+ description = None # type: Optional[str]
97 lockfilepath = None
98 loglevel = logging.INFO
99
100diff --git a/lib/lp/translations/browser/potemplate.py b/lib/lp/translations/browser/potemplate.py
101index fe4fb89..505672a 100644
102--- a/lib/lp/translations/browser/potemplate.py
103+++ b/lib/lp/translations/browser/potemplate.py
104@@ -603,10 +603,10 @@ class POTemplateEditView(ReturnToReferrerMixin, LaunchpadEditFormView):
105 if referrer is None:
106 # "referer" is misspelled in the HTTP specification.
107 referrer = self.request.getHeader("referer")
108- # If we were looking at the actual template, we want a new
109- # URL constructed.
110- if referrer is not None and "/+pots/" in referrer:
111- returnChanged = True
112+ # If we were looking at the actual template, we want a new URL
113+ # constructed.
114+ if referrer is not None and "/+pots/" in referrer:
115+ returnChanged = True
116
117 if (
118 referrer is not None
119@@ -758,11 +758,6 @@ class POTemplateEditView(ReturnToReferrerMixin, LaunchpadEditFormView):
120 "translation_domain", "Domain is already in use."
121 )
122
123- @property
124- def _return_attribute_name(self):
125- """See 'ReturnToReferrerMixin'."""
126- return "name"
127-
128
129 class POTemplateAdminView(POTemplateEditView):
130 """View class that lets you admin a POTemplate object."""

Subscribers

People subscribed via source and target branches

to status/vote changes: