Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'incompatible': 0.07; 'skip:` 10': 0.07; 'subject:code': 0.07; 'ugly': 0.07; 'versions,': 0.07; 'ambiguity': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'literal': 0.09; 'message-id:@stoneleaf.us': 0.09; 'parameter': 0.09; 'rejected': 0.09; 'satisfy': 0.09; 'subject:string': 0.09; 'subtle': 0.09; '~ethan~': 0.09; 'python': 0.11; 'bug': 0.12; '__future__': 0.16; 'buggy': 0.16; 'filename:fname piece:signature': 0.16; 'finney': 0.16; 'rather,': 0.16; 'subject: \n ': 0.16; 'subject:between': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'module': 0.19; 'import': 0.22; 'header:User- Agent:1': 0.23; 'bytes': 0.24; 'fixed.': 0.24; 'unicode': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; "i'm": 0.30; 'code': 0.31; '(maybe': 0.31; 'base,': 0.31; 'correctly.': 0.31; 'compatible': 0.32; 'stuff': 0.32; 'worked': 0.33; 'call.': 0.33; 'comment': 0.34; 'problem': 0.35; "can't": 0.35; 'but': 0.35; 'should': 0.36; 'requirements': 0.37; 'ben': 0.38; 'to:addr :python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'previous': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; '8bit%:6': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'around.': 0.60; 'course.': 0.60; 'received:173': 0.61; 'simple': 0.61; "you'll": 0.62; 'such': 0.63; 'charset:windows-1252': 0.65; 'increasingly': 0.84; 'skip:\x91 10': 0.84 Date: Mon, 15 Dec 2014 17:49:14 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Portable code: __import__ demands different string types between 2 and 3 References: <85wq5tpe0g.fsf@benfinney.id.au> <548F18FC.5040408@stoneleaf.us> <85iohcpe9n.fsf@benfinney.id.au> In-Reply-To: <85iohcpe9n.fsf@benfinney.id.au> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7jCLbTOg1SqEJraUQdvOmwsOAv134dKtH" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418694593 news.xs4all.nl 2875 [2001:888:2000:d::a6]:57512 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82571 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7jCLbTOg1SqEJraUQdvOmwsOAv134dKtH Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 12/15/2014 05:36 PM, Ben Finney wrote: >=20 > That's not the issue at all. I know how to declare a literal such that > it is Unicode in Python 2 and Python 3 (that's what the =91from __futur= e__ > import unicode_literals=92 does). >=20 > Rather, the problem is =91__import__=92 having incompatible expectation= s: > the =91fromlist=92 parameter's items must be bytes in Python 2, and mus= t be > Unicode in Python 3. Ah. Well, then you do not want the `unicode_literals` import or it won't= be bytes in Python 2 (as I'm sure you know). > The same parameter value can't satisfy both those requirements in a > single 2-and-3 compatible code base, without either using the > bytes-and-text ambiguity of =91str=92, or some kludge over-riding a sim= ple > =91__import__=92 call. Both of those are ugly and make for buggy code. If this is for a large(ish) application, make one module with stuff that = needs the ambiguity to work correctly. Comment the heck out of it. ;) > I'm increasingly of the opinion this is a subtle bug in =91__import__=92= > that should be fixed instead of worked around. Of course. But you'll still need to work around it for previous versions= , unless you can say you only support 2.7.10+ (maybe 2.7.9+ if it gets fixed quick enough). > But it will likely be rejected because the documentation advises agains= t using =91__import__=92. Functions that should accept str but barf on unicode have a tendency to g= et fixed. -- ~Ethan~ --7jCLbTOg1SqEJraUQdvOmwsOAv134dKtH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUj4+dAAoJENZ7D1rrH75NP8IQAJ3Y3Gy5aYRduxEnUoz5jcxS i1ZpEaSiY4gbdmzartI9d4jJMB5pUICqiUpm36jw3M04Ks6vGPxqLdBOMPj6xllx 4N/Emu1zTjK066xfBa5hSN6wrDe5Otcx2woVQ9Ya/UC2m4F47bsVc8l8CDy/+mvc ibsgWWJFY1xLZosJuP9U5H87ZwYzrkMvf3YIYsUmvkwAaIejesBVnZp0kX5dXMyl YLHrH11gOPoqNYg22QKCiT4m7Cp9jUR5ozj7vVwtxlULXd4BdqK0fspPoMpvoZXf t+LMWOl4fnkfkHgr4G1jBS8/HXj8GO1Dx9nLYqL8OmNfubD97bEvE/txnrIxk9dX hLmqWFIgnO3lwoRiyK31Vi9dlUnWLrBnEQd6ZixBvEZp26r4tTr+uSOobiHJYjYb b0WDTiPNEhgM3Xd63Px1UGZ2hlGZctElvHz/KOz8AoYomSdGJkxKBohaCbqg7UlW c9Nit8vg8oAuCeOWlvoymIOl/RY+3e74hUD+ECNcvD/Ss7gGPWlFjCVQ1PxxDhoE gFR6lWeYrkVynLsxyhw+ZOG0UuL1RVinAIP4+MwZLb2icJl4lhtSt0nlZyOz6g9A FvoPFyfwrWSYw7O0XfaMg/87t/lAV7kS8a8zloBVCRIlyUVla+MSxTzTZcKWw/Hs ePToG3LYOF7hNIDyh4Vt =e8PS -----END PGP SIGNATURE----- --7jCLbTOg1SqEJraUQdvOmwsOAv134dKtH--