From regebro at gmail.com Tue Apr 1 03:59:47 2014 From: regebro at gmail.com (Lennart Regebro) Date: Tue, 1 Apr 2014 03:59:47 +0200 Subject: [Python-porting] Doctests in single-source port In-Reply-To: References: Message-ID: There are a few here: http://python3porting.com/problems.html#running-doctests But several of them actually reduce doctests value as documentation, so it's not brilliant. On Mon, Mar 31, 2014 at 10:13 PM, Dirkjan Ochtman wrote: > Hi there, > > I've just had another run at completing my single-source port of > CouchDB-Python (see [1]), trying to converge on something that passes > the test suite on both 2.7 and 3.3. However, I can't think of any > clever ways to deal with doctest failures I'm seeing. Are there any > established best practices or ugly hacks to make this easier? Here are > some typical failures: > > ====================================================================== > FAIL: delete (couchdb.client.Database) > Doctest: couchdb.client.Database.delete > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.3/doctest.py", line 2154, in runTest > raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for couchdb.client.Database.delete > File "./couchdb/client.py", line 512, in delete > > ---------------------------------------------------------------------- > File "./couchdb/client.py", line 528, in couchdb.client.Database.delete > Failed example: > db.delete(doc) > Expected: > Traceback (most recent call last): > ... > ResourceConflict: (u'conflict', u'Document update conflict.') > Got: > Traceback (most recent call last): > File "/usr/lib/python3.3/doctest.py", line 1287, in __run > compileflags, 1), test.globs) > File "", line 1, in > db.delete(doc) > File "./couchdb/client.py", line 541, in delete > _doc_resource(self.resource, doc['_id']).delete_json(rev=doc['_rev']) > File "./couchdb/http.py", line 530, in delete_json > return self._request_json('DELETE', path, headers=headers, **params) > File "./couchdb/http.py", line 556, in _request_json > headers=headers, **params) > File "./couchdb/http.py", line 552, in _request > credentials=self.credentials) > File "./couchdb/http.py", line 404, in request > raise ResourceConflict(error) > couchdb.http.ResourceConflict: ('conflict', 'Document update conflict.') > > FAIL: ViewResults (couchdb.client) > Doctest: couchdb.client.ViewResults > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python3.3/doctest.py", line 2154, in runTest > raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for couchdb.client.ViewResults > File "./couchdb/client.py", line 1097, in ViewResults > > ---------------------------------------------------------------------- > File "./couchdb/client.py", line 1136, in couchdb.client.ViewResults > Failed example: > list(results[['City', 'Gotham City']]) > Expected: > [] > Got: > [] > > Thanks for any suggestions, > > Dirkjan > > [1] https://code.google.com/p/couchdb-python/source/list?name=db566517e8af > _______________________________________________ > Python-porting mailing list > Python-porting at python.org > https://mail.python.org/mailman/listinfo/python-porting From ethan at stoneleaf.us Tue Apr 1 23:19:16 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 01 Apr 2014 14:19:16 -0700 Subject: [Python-porting] questions about future package here? In-Reply-To: References: Message-ID: <533B2D54.7030800@stoneleaf.us> On 03/31/2014 12:34 PM, Neal Becker wrote: > > So what is this newint anyway? I haven't looked at the code, but I would guess it's the 'long' type. I would also guess that numpy really wants an int, not a long. But that's all just guesses. -- ~Ethan~ P.S. I'm sending directly to Neil as my ML post still hasn't shown up after a couple days. From ed at pythoncharmers.com Sun Apr 13 03:22:37 2014 From: ed at pythoncharmers.com (Ed Schofield) Date: Sun, 13 Apr 2014 11:22:37 +1000 Subject: [Python-porting] Fwd: questions about future package here? References: <6C601667-DEA9-42D6-961F-0B79CD00A1BF@pythoncharmers.com> Message-ID: <2EB7BAC1-39CD-46BD-AAE8-A2BE6096677E@pythoncharmers.com> Hi everyone, It seems I forgot to CC the list. Here was my reply to Neal: > I'm just experimenting with future package. > > 1st problem: > I tried converting a small py2 module > futurize mod.py -w > > Then I get segfault. It seems to want to do: > > from future.builtins import int > > Then when my code says: > > .astype(int) > > instead of converting to int, it is converted to object. > > So what is this newint anyway? Thanks for your question. ``newint`` is simply a subclass of ``long`` on Python 2 that behaves more like Python 3?s ``int``. It?s pure-Python, so it won?t be causing any segfaults by itself. It is either NumPy or (perhaps more likely) some custom C code that is segfaulting when it gets a NumPy array of dtype object that it doesn?t handle. It seems that the astype method of ndarray understands ``long`` objects as a dtype on Py2 and interprets them as np.int64 objects, but it doesn?t handle subclasses of ``long``. Here is a minimal example that reproduces the problem: ``` class longsubclass(long): pass def test_numpy_cast_as_long(): import numpy as np a = np.arange(100, dtype=np.float64) b = a.astype(long) c = a.astype(longsubclass) assert b.dtype == c.dtype test_numpy_cast_as_long() # fails ``` Ideally NumPy would be tweaked so that it interprets subclasses of the Python data types similarly to the base types. As a simple workaround for your code for now, you could either use .astype(np.int64) or just remove the ``future.builtins.int`` import if you don?t need it. See here for more info on what it does. Best wishes, Ed -- Dr. Edward Schofield Python Charmers +61 (0)405 676 229 http://pythoncharmers.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From guido at python.org Mon Apr 21 21:36:09 2014 From: guido at python.org (Guido van Rossum) Date: Mon, 21 Apr 2014 12:36:09 -0700 Subject: [Python-porting] [Baypiggies] Is there any guide or post to follow in order to write code that works both on python 2 and 3? In-Reply-To: References: Message-ID: The commonly recommended resource is http://python3porting.com/ Also make sure to get to 100% test coverage! On Mon, Apr 21, 2014 at 12:31 PM, Santiago Basulto < santiago.basulto at gmail.com> wrote: > Hello everyone. I'm writing a library that I'd like to be usable from > both, Python 2 and Python 3. Actually, there's a library that works just > for python2 and I want to make it work for 3. > > I know it's not really hard to make it work for both versions, but > sometimes I have doubts. For example. If I define a simple class: > > class A: > def __init__(self): > pass > > It will have different meanings if it's run with Python 2 or Python 3 > (lacking 'object' inheritence for python2). > > Is there any guide, blog post, anything? > > Thank you very much. > > -- > Santiago Basulto.- > > _______________________________________________ > Baypiggies mailing list > Baypiggies at python.org > To change your subscription options or unsubscribe: > https://mail.python.org/mailman/listinfo/baypiggies > -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From asmeurer at gmail.com Mon Apr 21 22:13:02 2014 From: asmeurer at gmail.com (Aaron Meurer) Date: Mon, 21 Apr 2014 15:13:02 -0500 Subject: [Python-porting] [Baypiggies] Is there any guide or post to follow in order to write code that works both on python 2 and 3? In-Reply-To: References: Message-ID: For Python 2 compatible code, you should always be explicit and subclass every class from object, like class A(object): def __init__(self): pass This is one of the easy things for writing cross compatible code. The hard things are dealing with the str/bytes differences, and the little tricks you have to do to support metaclasses and exec. Aaron Meurer On Mon, Apr 21, 2014 at 2:36 PM, Guido van Rossum wrote: > The commonly recommended resource is http://python3porting.com/ > > Also make sure to get to 100% test coverage! > > > On Mon, Apr 21, 2014 at 12:31 PM, Santiago Basulto > wrote: >> >> Hello everyone. I'm writing a library that I'd like to be usable from >> both, Python 2 and Python 3. Actually, there's a library that works just for >> python2 and I want to make it work for 3. >> >> I know it's not really hard to make it work for both versions, but >> sometimes I have doubts. For example. If I define a simple class: >> >> class A: >> def __init__(self): >> pass >> >> It will have different meanings if it's run with Python 2 or Python 3 >> (lacking 'object' inheritence for python2). >> >> Is there any guide, blog post, anything? >> >> Thank you very much. >> >> -- >> Santiago Basulto.- >> >> _______________________________________________ >> Baypiggies mailing list >> Baypiggies at python.org >> To change your subscription options or unsubscribe: >> https://mail.python.org/mailman/listinfo/baypiggies > > > > > -- > --Guido van Rossum (python.org/~guido) > > _______________________________________________ > Python-porting mailing list > Python-porting at python.org > https://mail.python.org/mailman/listinfo/python-porting > From santiago.basulto at gmail.com Mon Apr 21 21:31:40 2014 From: santiago.basulto at gmail.com (Santiago Basulto) Date: Mon, 21 Apr 2014 16:31:40 -0300 Subject: [Python-porting] Is there any guide or post to follow in order to write code that works both on python 2 and 3? Message-ID: Hello everyone. I'm writing a library that I'd like to be usable from both, Python 2 and Python 3. Actually, there's a library that works just for python2 and I want to make it work for 3. I know it's not really hard to make it work for both versions, but sometimes I have doubts. For example. If I define a simple class: class A: def __init__(self): pass It will have different meanings if it's run with Python 2 or Python 3 (lacking 'object' inheritence for python2). Is there any guide, blog post, anything? Thank you very much. -- Santiago Basulto.- -------------- next part -------------- An HTML attachment was scrubbed... URL: From santiago.basulto at gmail.com Mon Apr 21 21:39:52 2014 From: santiago.basulto at gmail.com (Santiago Basulto) Date: Mon, 21 Apr 2014 16:39:52 -0300 Subject: [Python-porting] [Baypiggies] Is there any guide or post to follow in order to write code that works both on python 2 and 3? In-Reply-To: References: Message-ID: Shaleh, really useful. Thank you! Guido, you remind me something. I'll use Tox of course. Thanks for your advice. BTW. I'm new to the baypiggies ML. I'm from Argentina. You're all really kind. This is one of the things that makes Python so awesome. On Mon, Apr 21, 2014 at 4:36 PM, Guido van Rossum wrote: > The commonly recommended resource is http://python3porting.com/ > > Also make sure to get to 100% test coverage! > > > On Mon, Apr 21, 2014 at 12:31 PM, Santiago Basulto < > santiago.basulto at gmail.com> wrote: > >> Hello everyone. I'm writing a library that I'd like to be usable from >> both, Python 2 and Python 3. Actually, there's a library that works just >> for python2 and I want to make it work for 3. >> >> I know it's not really hard to make it work for both versions, but >> sometimes I have doubts. For example. If I define a simple class: >> >> class A: >> def __init__(self): >> pass >> >> It will have different meanings if it's run with Python 2 or Python 3 >> (lacking 'object' inheritence for python2). >> >> Is there any guide, blog post, anything? >> >> Thank you very much. >> >> -- >> Santiago Basulto.- >> >> _______________________________________________ >> Baypiggies mailing list >> Baypiggies at python.org >> To change your subscription options or unsubscribe: >> https://mail.python.org/mailman/listinfo/baypiggies >> > > > > -- > --Guido van Rossum (python.org/~guido) > -- Santiago Basulto.- -------------- next part -------------- An HTML attachment was scrubbed... URL: From shaleh at speakeasy.net Mon Apr 21 21:34:58 2014 From: shaleh at speakeasy.net (shaleh at speakeasy.net) Date: Mon, 21 Apr 2014 12:34:58 -0700 Subject: [Python-porting] [Baypiggies] Is there any guide or post to follow in order to writecode that works both on python 2 and 3? In-Reply-To: References: Message-ID: <20140421123458.v5hu5tojqg0ok4o4@mail.speakeasy.net> On Mon, 21 Apr 2014 16:31:40 -0300, Santiago Basulto wrote: Hello everyone. I'm writing a library that I'd like to be usable from both, Python 2 and Python 3. Actually, there's a library that works just for python2 and I want to make it work for 3. I know it's not really hard to make it work for both versions, but sometimes I have doubts. For example. If I define a simple class: class A: ? ? def __init__(self): ? ? ? ? pass It will have different meanings if it's run with Python 2 or Python 3 (lacking 'object' inheritence for python2). Is there any guide, blog post, anything? Is this enough or do you need more? http://python3porting.com/noconv.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From buck.2019 at gmail.com Tue Apr 29 22:31:53 2014 From: buck.2019 at gmail.com (Buck Golemon) Date: Tue, 29 Apr 2014 13:31:53 -0700 Subject: [Python-porting] porting %s for bytes Message-ID: We're working on porting MySQLdb, and run up against a hard wall in %s in bytestrings. SQL queries are truly bytes (they can contain arbitrary binary blobs for insertion), but also need substition operations. The substition scheme in MySQLdb is %s. This was handy when we could do query_bytesring % params, but makes things very tough in python3. My options seem to be: A) Somehow decode arbitrary bytes to str, do the substitution, and encode back to bytes. I can use the 'sorrogateescape' erorr handler to do this in python3, but since this doesn't existing in 2.6 or 2.7, it doesn't jive with my goals of 2+3 support. B) Implement modulo substitution for bytes in python3. I see that this operation is making a reappearance in python3.5, so this seems fairly reasonable: http://legacy.python.org/dev/peps/pep-0461/ I'm using the `future` package to do the port, and am very pleased with the result, but it doesn't handle this one rough spot. Can I request a 2+3 implementation of bytes.__mod__? Or, has anyone seen a currently-existing implementation of this function? -------------- next part -------------- An HTML attachment was scrubbed... URL: