"Mark Dickinson" <dickinsm at gmail.com> wrote in message news:5c6f2a5d0803250853g4814eac6n25b07326f2e7805d at mail.gmail.com... | On Tue, Mar 25, 2008 at 11:29 AM, Nick Coghlan <ncoghlan at gmail.com> wrote: | | > The isinstance(value, str) check in Py3k is too restrictive - it needs | > to accept bytes instances as well. | > | | Hmm. There's not a lot of consistency here: | | >>> int(b'1') | 1 | >>> float(b'1') | 1.0 | >>> complex(b'1') | Traceback (most recent call last): | File "<stdin>", line 1, in <module> | TypeError: complex() argument must be a string or a number | >>> from fractions import Fraction | >>> Fraction(b'1') | Traceback (most recent call last): | File "<stdin>", line 1, in <module> | File "/Users/dickinsm/python_source/py3k/Lib/fractions.py", line 98, in | __new__ | numerator = numerator.__index__() | AttributeError: 'bytes' object has no attribute '__index__' | | So int and float accepts bytes, while complex, Decimal and Fraction do | not... The purpose of type constructors is to construct instances from reasonable inputs. I think all number constructors should accept bytes and so the latter three should be changed. tjr
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4