Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 preparation: Py2 vs. Py3 return value of write() in doctests #16086

Closed
wluebbe mannequin opened this issue Apr 7, 2014 · 12 comments
Closed

Python 3 preparation: Py2 vs. Py3 return value of write() in doctests #16086

wluebbe mannequin opened this issue Apr 7, 2014 · 12 comments

Comments

@wluebbe
Copy link
Mannequin

wluebbe mannequin commented Apr 7, 2014

The write() function does return nothing in Py2

>>> sys.version
'2.7.5+ (default, Feb 27 2014, 19:37:08) \n[GCC 4.8.1]'
>>> with open("tracked", "w") as f: f.write("boo")
... 
>>> 

while in Py3 it returns the number of bytes written

>>> sys.version
'3.3.2+ (default, Feb 28 2014, 00:52:16) \n[GCC 4.8.1]'
>>> with open("tracked", "w") as f: f.write("boo")
... 
3
>>> 

This can be unified by adding something like ignore =

>>> sys.version
'3.3.2+ (default, Feb 28 2014, 00:52:16) \n[GCC 4.8.1]'
>>> with open("tracked", "w") as f: ignore = f.write("boo")
... 
>>> 

About 79 py module are effected.

This ticket is tracked as a dependency of meta-ticket ticket:16052.

Component: python3

Author: John Palmieri

Branch/Commit: 0234816

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/16086

@wluebbe wluebbe mannequin added this to the sage-6.2 milestone Apr 7, 2014
@wluebbe wluebbe mannequin added c: distribution labels Apr 7, 2014
@wluebbe

This comment has been minimized.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jhpalmieri
Copy link
Member

Branch: u/jhpalmieri/ignore_write_output

@jhpalmieri
Copy link
Member

Commit: d020f64

@jhpalmieri
Copy link
Member

Author: John Palmieri

@jhpalmieri
Copy link
Member

New commits:

d020f64trac 16086: In Python 3, FILE.write('...') has a return value: the

@jhpalmieri
Copy link
Member

comment:7

I used _ = file.open('...'), since _ is commonly used as an ignored variable in Python. Also, _ has a special meaning at the command line: the result of the previous command. But _ is treated differently in doctesting: in libs/pari/tests.py, if I use

    sage: _ = gpfile.file.write("polcyclo(5)\n")

on line 187, then on line 377,

    sage: _.Strchr()

the doctesting framework thinks that _ still refers to the result of the call to write. I would say this is a bug in the doctesting framework. To get around it, I used a double underscore on line 187 (and the previous few lines) in lib/pari/tests.py.

@tscrim
Copy link
Collaborator

tscrim commented Apr 24, 2017

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Apr 24, 2017

comment:8

Needs a rebase, but LGTM otherwise.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 24, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

0234816Merge branch 'develop' into t/16086/ignore_write_output

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Apr 24, 2017

Changed commit from d020f64 to 0234816

@jhpalmieri
Copy link
Member

comment:10

Okay, rebased.

@vbraun
Copy link
Member

vbraun commented Apr 25, 2017

Changed branch from u/jhpalmieri/ignore_write_output to 0234816

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants