Skip to content

Commit ad57a78

Browse files
committed
vector*.py: simplifica conversão para bytes
1 parent 1097a59 commit ad57a78

File tree

17 files changed

+22
-22
lines changed

17 files changed

+22
-22
lines changed

code/11-pythonic-obj/vector2d_v0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __str__(self):
5050
return str(tuple(self)) # <5>
5151

5252
def __bytes__(self):
53-
return (bytes([ord(self.typecode)]) + # <6>
53+
return (self.typecode.encode('ascii') + # <6>
5454
bytes(array(self.typecode, self))) # <7>
5555

5656
def __eq__(self, other):

code/11-pythonic-obj/vector2d_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __str__(self):
5555
return str(tuple(self))
5656

5757
def __bytes__(self):
58-
return (bytes([ord(self.typecode)]) +
58+
return (self.typecode.encode('ascii') +
5959
bytes(array(self.typecode, self)))
6060

6161
def __eq__(self, other):

code/11-pythonic-obj/vector2d_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __str__(self):
8989
return str(tuple(self))
9090

9191
def __bytes__(self):
92-
return (bytes([ord(self.typecode)]) +
92+
return (self.typecode.encode('ascii') +
9393
bytes(array(self.typecode, self)))
9494

9595
def __eq__(self, other):

code/11-pythonic-obj/vector2d_v3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
>>> v1.x = 123
7373
Traceback (most recent call last):
7474
...
75-
AttributeError: can't set attribute 'x'
75+
AttributeError: property 'x' of 'Vector2d' object has no setter
7676
7777
7878
Tests of hashing:
@@ -115,7 +115,7 @@ def __str__(self):
115115
return str(tuple(self))
116116

117117
def __bytes__(self):
118-
return (bytes([ord(self.typecode)]) +
118+
return (self.typecode.encode('ascii') +
119119
bytes(array(self.typecode, self)))
120120

121121
def __eq__(self, other):

code/11-pythonic-obj/vector2d_v3_prophash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
>>> v1.x = 123
7373
Traceback (most recent call last):
7474
...
75-
AttributeError: can't set attribute 'x'
75+
AttributeError: property 'x' of 'Vector2d' object has no setter
7676
7777
# end::VECTOR2D_V3_HASH_DEMO[]
7878
@@ -121,7 +121,7 @@ def __str__(self):
121121
return str(tuple(self))
122122

123123
def __bytes__(self):
124-
return (bytes([ord(self.typecode)]) +
124+
return (self.typecode.encode('ascii') +
125125
bytes(array(self.typecode, self)))
126126

127127
def __eq__(self, other):

code/11-pythonic-obj/vector2d_v3_slots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
>>> v1.x = 123
7373
Traceback (most recent call last):
7474
...
75-
AttributeError: can't set attribute 'x'
75+
AttributeError: property 'x' of 'Vector2d' object has no setter
7676
7777
Tests of hashing:
7878
@@ -117,7 +117,7 @@ def __str__(self):
117117
return str(tuple(self))
118118

119119
def __bytes__(self):
120-
return (bytes([ord(self.typecode)]) +
120+
return (self.typecode.encode('ascii') +
121121
bytes(array(self.typecode, self)))
122122

123123
def __eq__(self, other):

code/12-seq-hacking/vector_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __str__(self):
106106
return str(tuple(self))
107107

108108
def __bytes__(self):
109-
return (bytes([ord(self.typecode)]) +
109+
return (self.typecode.encode('ascii') +
110110
bytes(self._components)) # <5>
111111

112112
def __eq__(self, other):

code/12-seq-hacking/vector_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __str__(self):
133133
return str(tuple(self))
134134

135135
def __bytes__(self):
136-
return (bytes([ord(self.typecode)]) +
136+
return (self.typecode.encode('ascii') +
137137
bytes(self._components))
138138

139139
def __eq__(self, other):

code/12-seq-hacking/vector_v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __str__(self):
176176
return str(tuple(self))
177177

178178
def __bytes__(self):
179-
return (bytes([ord(self.typecode)]) +
179+
return (self.typecode.encode('ascii') +
180180
bytes(self._components))
181181

182182
def __eq__(self, other):

code/12-seq-hacking/vector_v4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __str__(self):
172172
return str(tuple(self))
173173

174174
def __bytes__(self):
175-
return (bytes([ord(self.typecode)]) +
175+
return (self.typecode.encode('ascii') +
176176
bytes(self._components))
177177

178178
def __eq__(self, other):

0 commit comments

Comments
 (0)