Skip to content

Commit bdccc32

Browse files
committed
update from Atlas
1 parent cf96836 commit bdccc32

25 files changed

+393
-46
lines changed
File renamed without changes.

classes/vector_v2.py renamed to 10-seq-hacking/vector_v2.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
from array import array
113113
import reprlib
114114
import math
115+
import numbers
115116

116117

117118
class Vector:
@@ -150,13 +151,13 @@ def __len__(self):
150151

151152
def __getitem__(self, index):
152153
cls = type(self) # <1>
153-
if isinstance(index, slice):
154-
return cls(self._components[index]) # <2>
155-
elif isinstance(index, int):
156-
return self._components[index] # <3>
154+
if isinstance(index, slice): # <2>
155+
return cls(self._components[index]) # <3>
156+
elif isinstance(index, numbers.Integral): # <4>
157+
return self._components[index] # <5>
157158
else:
158159
msg = '{cls.__name__} indices must be integers'
159-
raise TypeError(msg.format(cls=cls)) # <4>
160+
raise TypeError(msg.format(cls=cls)) # <6>
160161
# END VECTOR_V2
161162

162163
@classmethod

classes/vector_v3.py renamed to 10-seq-hacking/vector_v3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
from array import array
156156
import reprlib
157157
import math
158+
import numbers
158159

159160

160161
class Vector:
@@ -194,7 +195,7 @@ def __getitem__(self, index):
194195
cls = type(self)
195196
if isinstance(index, slice):
196197
return cls(self._components[index])
197-
elif isinstance(index, int):
198+
elif isinstance(index, numbers.Integral):
198199
return self._components[index]
199200
else:
200201
msg = '{.__name__} indices must be integers'

classes/vector_v4.py renamed to 10-seq-hacking/vector_v4.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,22 @@
135135
>>> v2 = Vector([3.1, 4.2])
136136
>>> v3 = Vector([3, 4, 5])
137137
>>> v6 = Vector(range(6))
138-
>>> hash(v1), hash(v2), hash(v3), hash(v6)
139-
(7, 384307168202284039, 2, 1)
140-
>>> len(set([v1, v2, v3, v6]))
141-
4
138+
>>> hash(v1), hash(v3), hash(v6)
139+
(7, 2, 1)
142140
143141
142+
Most hash values of non-integers vary from a 32-bit to 64-bit CPython build::
143+
144+
>>> import sys
145+
>>> hash(v2) == (384307168202284039 if sys.maxsize > 2**32 else 357915986)
146+
True
147+
144148
"""
145149

146150
from array import array
147151
import reprlib
148152
import math
153+
import numbers
149154
import functools
150155
import operator
151156

@@ -192,11 +197,11 @@ def __getitem__(self, index):
192197
cls = type(self)
193198
if isinstance(index, slice):
194199
return cls(self._components[index])
195-
elif isinstance(index, int):
200+
elif isinstance(index, numbers.Integral):
196201
return self._components[index]
197202
else:
198-
msg = '{.__name__} indices must be integers'
199-
raise TypeError(msg.format(cls))
203+
msg = '{cls.__name__} indices must be integers'
204+
raise TypeError(msg.format(cls=cls))
200205

201206
shortcut_names = 'xyzt'
202207

classes/vector_v5.py renamed to 10-seq-hacking/vector_v5.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@
136136
>>> v2 = Vector([3.1, 4.2])
137137
>>> v3 = Vector([3, 4, 5])
138138
>>> v6 = Vector(range(6))
139-
>>> hash(v1), hash(v2), hash(v3), hash(v6)
140-
(7, 384307168202284039, 2, 1)
141-
>>> len(set([v1, v2, v3, v6]))
142-
4
139+
>>> hash(v1), hash(v3), hash(v6)
140+
(7, 2, 1)
141+
142+
143+
Most hash values of non-integers vary from a 32-bit to 64-bit CPython build::
144+
145+
>>> import sys
146+
>>> hash(v2) == (384307168202284039 if sys.maxsize > 2**32 else 357915986)
147+
True
143148
144149
145150
Tests of ``format()`` with Cartesian coordinates in 2D::
@@ -187,6 +192,7 @@
187192
from array import array
188193
import reprlib
189194
import math
195+
import numbers
190196
import functools
191197
import operator
192198
import itertools # <1>
@@ -234,7 +240,7 @@ def __getitem__(self, index):
234240
cls = type(self)
235241
if isinstance(index, slice):
236242
return cls(self._components[index])
237-
elif isinstance(index, int):
243+
elif isinstance(index, numbers.Integral):
238244
return self._components[index]
239245
else:
240246
msg = '{.__name__} indices must be integers'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)