Opened 8 years ago
Closed 5 years ago
#16086 closed enhancement (fixed)
Python 3 preparation: Py2 vs. Py3 return value of write() in doctests
Reported by: | wluebbe | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.0 |
Component: | python3 | Keywords: | python3 |
Cc: | Merged in: | ||
Authors: | John Palmieri | Reviewers: | Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | 0234816 (Commits, GitHub, GitLab) | Commit: | 0234816c91fc2de8930682281f72f6b8d2a750a9 |
Dependencies: | Stopgaps: |
Description (last modified by )
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.
Change History (12)
comment:1 Changed 8 years ago by
- Description modified (diff)
comment:2 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:3 Changed 8 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:4 Changed 6 years ago by
- Component changed from distribution to python3
comment:5 Changed 5 years ago by
- Branch set to u/jhpalmieri/ignore_write_output
comment:6 Changed 5 years ago by
- Commit set to d020f64044e48572b161a991b786b971494a4366
- Milestone changed from sage-6.4 to sage-8.0
- Status changed from new to needs_review
comment:7 Changed 5 years ago by
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
.
comment:8 Changed 5 years ago by
- Reviewers set to Travis Scrimshaw
Needs a rebase, but LGTM otherwise.
comment:9 Changed 5 years ago by
- Commit changed from d020f64044e48572b161a991b786b971494a4366 to 0234816c91fc2de8930682281f72f6b8d2a750a9
Branch pushed to git repo; I updated commit sha1. New commits:
0234816 | Merge branch 'develop' into t/16086/ignore_write_output
|
comment:10 Changed 5 years ago by
Okay, rebased.
comment:11 Changed 5 years ago by
- Status changed from needs_review to positive_review
comment:12 Changed 5 years ago by
- Branch changed from u/jhpalmieri/ignore_write_output to 0234816c91fc2de8930682281f72f6b8d2a750a9
- Resolution set to fixed
- Status changed from positive_review to closed
New commits:
trac 16086: In Python 3, FILE.write('...') has a return value: the