Merge lp:~cjwatson/storm/py3-raise into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 510
Proposed branch: lp:~cjwatson/storm/py3-raise
Merge into: lp:storm
Diff against target: 196 lines (+39/-36)
2 files modified
storm/schema/patch.py (+7/-4)
storm/tz.py (+32/-32)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-raise
Reviewer Review Type Date Requested Status
Simon Poirier (community) Approve
Review via email: mp+371121@code.launchpad.net

Commit message

Use Python 3-compatible raise syntax.

Description of the change

Mostly extracted from https://bazaar.launchpad.net/~bellini666/storm/py3/revision/485, with an extra commit where I used six rather than future.

To post a comment you must log in.
Revision history for this message
Simon Poirier (simpoir) wrote :

+1 LGTM

also, thanks for fixing the indentation :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/schema/patch.py'
2--- storm/schema/patch.py 2019-06-05 11:41:07 +0000
3+++ storm/schema/patch.py 2019-08-09 13:15:52 +0000
4@@ -41,6 +41,8 @@
5 import re
6 import types
7
8+import six
9+
10 from storm.locals import StormError, Int
11
12
13@@ -120,10 +122,11 @@
14 except:
15 type, value, traceback = sys.exc_info()
16 patch_repr = getattr(module, "__file__", version)
17- raise BadPatchError, \
18- "Patch %s failed: %s: %s" % \
19- (patch_repr, type.__name__, str(value)), \
20- traceback
21+ six.reraise(
22+ BadPatchError,
23+ "Patch %s failed: %s: %s" %
24+ (patch_repr, type.__name__, str(value)),
25+ traceback)
26 self._committer.commit()
27
28 def apply_all(self):
29
30=== modified file 'storm/tz.py'
31--- storm/tz.py 2019-06-06 09:03:07 +0000
32+++ storm/tz.py 2019-08-09 13:15:52 +0000
33@@ -215,7 +215,7 @@
34 # of the value is written first).
35
36 if fileobj.read(4) != "TZif":
37- raise ValueError, "magic not found"
38+ raise ValueError("magic not found")
39
40 fileobj.read(16)
41
42@@ -471,7 +471,7 @@
43
44 def __reduce__(self):
45 if not os.path.isfile(self._filename):
46- raise ValueError, "Unpickable %s class" % self.__class__.__name__
47+ raise ValueError("Unpickable %s class" % self.__class__.__name__)
48 return (self.__class__, (self._filename,))
49
50 class tzrange(datetime.tzinfo):
51@@ -563,7 +563,7 @@
52
53 res = parser._parsetz(s)
54 if res is None:
55- raise ValueError, "unknown string format"
56+ raise ValueError("unknown string format")
57
58 # We must initialize it first, since _delta() needs
59 # _std_offset and _dst_offset set. Use False in start/end
60@@ -725,7 +725,7 @@
61 def _parse_offset(self, s):
62 s = s.strip()
63 if not s:
64- raise ValueError, "empty offset"
65+ raise ValueError("empty offset")
66 if s[0] in ('+', '-'):
67 signal = (-1,+1)[s[0]=='+']
68 s = s[1:]
69@@ -736,12 +736,12 @@
70 elif len(s) == 6:
71 return (int(s[:2])*3600+int(s[2:4])*60+int(s[4:]))*signal
72 else:
73- raise ValueError, "invalid offset: "+s
74+ raise ValueError("invalid offset: "+s)
75
76 def _parse_rfc(self, s):
77 lines = s.splitlines()
78 if not lines:
79- raise ValueError, "empty string"
80+ raise ValueError("empty string")
81
82 # Unfold
83 i = 0
84@@ -765,7 +765,7 @@
85 name, value = line.split(':', 1)
86 parms = name.split(';')
87 if not parms:
88- raise ValueError, "empty property name"
89+ raise ValueError("empty property name")
90 name = parms[0].upper()
91 parms = parms[1:]
92 if invtz:
93@@ -774,7 +774,7 @@
94 # Process component
95 pass
96 else:
97- raise ValueError, "unknown component: "+value
98+ raise ValueError("unknown component: "+value)
99 comptype = value
100 founddtstart = False
101 tzoffsetfrom = None
102@@ -784,27 +784,27 @@
103 elif name == "END":
104 if value == "VTIMEZONE":
105 if comptype:
106- raise ValueError, \
107- "component not closed: "+comptype
108+ raise ValueError(
109+ "component not closed: "+comptype)
110 if not tzid:
111- raise ValueError, \
112- "mandatory TZID not found"
113+ raise ValueError(
114+ "mandatory TZID not found")
115 if not comps:
116- raise ValueError, \
117- "at least one component is needed"
118+ raise ValueError(
119+ "at least one component is needed")
120 # Process vtimezone
121 self._vtz[tzid] = _tzicalvtz(tzid, comps)
122 invtz = False
123 elif value == comptype:
124 if not founddtstart:
125- raise ValueError, \
126- "mandatory DTSTART not found"
127+ raise ValueError(
128+ "mandatory DTSTART not found")
129 if tzoffsetfrom is None:
130- raise ValueError, \
131- "mandatory TZOFFSETFROM not found"
132+ raise ValueError(
133+ "mandatory TZOFFSETFROM not found")
134 if tzoffsetto is None:
135- raise ValueError, \
136- "mandatory TZOFFSETFROM not found"
137+ raise ValueError(
138+ "mandatory TZOFFSETFROM not found")
139 # Process component
140 rr = None
141 if rrulelines:
142@@ -818,8 +818,8 @@
143 comps.append(comp)
144 comptype = None
145 else:
146- raise ValueError, \
147- "invalid component end: "+value
148+ raise ValueError(
149+ "invalid component end: "+value)
150 elif comptype:
151 if name == "DTSTART":
152 rrulelines.append(line)
153@@ -828,33 +828,33 @@
154 rrulelines.append(line)
155 elif name == "TZOFFSETFROM":
156 if parms:
157- raise ValueError, \
158- "unsupported %s parm: %s "%(name, parms[0])
159+ raise ValueError(
160+ "unsupported %s parm: %s "%(name, parms[0]))
161 tzoffsetfrom = self._parse_offset(value)
162 elif name == "TZOFFSETTO":
163 if parms:
164- raise ValueError, \
165- "unsupported TZOFFSETTO parm: "+parms[0]
166+ raise ValueError(
167+ "unsupported TZOFFSETTO parm: "+parms[0])
168 tzoffsetto = self._parse_offset(value)
169 elif name == "TZNAME":
170 if parms:
171- raise ValueError, \
172- "unsupported TZNAME parm: "+parms[0]
173+ raise ValueError(
174+ "unsupported TZNAME parm: "+parms[0])
175 tzname = value
176 elif name == "COMMENT":
177 pass
178 else:
179- raise ValueError, "unsupported property: "+name
180+ raise ValueError("unsupported property: "+name)
181 else:
182 if name == "TZID":
183 if parms:
184- raise ValueError, \
185- "unsupported TZID parm: "+parms[0]
186+ raise ValueError(
187+ "unsupported TZID parm: "+parms[0])
188 tzid = value
189 elif name in ("TZURL", "LAST-MODIFIED", "COMMENT"):
190 pass
191 else:
192- raise ValueError, "unsupported property: "+name
193+ raise ValueError("unsupported property: "+name)
194 elif name == "BEGIN" and value == "VTIMEZONE":
195 tzid = None
196 comps = []

Subscribers

People subscribed via source and target branches

to status/vote changes: