Show More
@@ -203,6 +203,13 b' class bytestr(bytes):' | |||||
203 | >>> bytestr(bytesable()) |
|
203 | >>> bytestr(bytesable()) | |
204 | 'bytes' |
|
204 | 'bytes' | |
205 |
|
205 | |||
|
206 | ...unless the argument is the bytes *type* itself: it gets a | |||
|
207 | __bytes__() method in Python 3.11, which cannot be used as in an instance | |||
|
208 | of bytes: | |||
|
209 | ||||
|
210 | >>> bytestr(bytes) | |||
|
211 | "<class 'bytes'>" | |||
|
212 | ||||
206 | There's no implicit conversion from non-ascii str as its encoding is |
|
213 | There's no implicit conversion from non-ascii str as its encoding is | |
207 | unknown: |
|
214 | unknown: | |
208 |
|
215 | |||
@@ -252,10 +259,9 b' class bytestr(bytes):' | |||||
252 | def __new__(cls: Type[_Tbytestr], s: object = b'') -> _Tbytestr: |
|
259 | def __new__(cls: Type[_Tbytestr], s: object = b'') -> _Tbytestr: | |
253 | if isinstance(s, bytestr): |
|
260 | if isinstance(s, bytestr): | |
254 | return s |
|
261 | return s | |
255 | if not isinstance( |
|
262 | if not isinstance(s, (bytes, bytearray)) and ( | |
256 | s, (bytes, bytearray) |
|
263 | isinstance(s, type) | |
257 |
|
|
264 | or not builtins.hasattr(s, u'__bytes__') # hasattr-py3-only | |
258 | s, u'__bytes__' |
|
|||
259 | ): |
|
265 | ): | |
260 | s = str(s).encode('ascii') |
|
266 | s = str(s).encode('ascii') | |
261 | return bytes.__new__(cls, s) |
|
267 | return bytes.__new__(cls, s) |
General Comments 0
You need to be logged in to leave comments.
Login now