-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
py3: better backwards-compatibility for Python longs #24559
Comments
Dependencies: #24258 |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:3
I don't really with the condition deprecation depending on |
comment:4
Replying to @jdemeyer:
This was added very deliberately in part to help with porting the doctests, so as to allow the great many doctests that use My intention, though not explicitly stated, was to later (once we want to switch Sage to Python 3) remove the condition so that it's easy to find and fix/remove such tests later. |
comment:5
Replying to @embray:
I think it's better to just enable the alias now without any deprecation and then later add an unconditional deprecation. Since Sage doesn't really support Python 3 for the moment, the deprecation won't have much effect anyway. |
comment:6
Why do you think that's better? Why is this wrong? |
comment:7
There's a difference between "supporting Python 3" and "having Python 3 as the default Sage". I think in some version--hopefully before long (I'm running pretty low on obvious errors to fix, and most of the problems I'm seeing are minor issues in doctests) there will be a Sage that supports Python 3. For backwards compatibility we'll want to keep Python 2 as the default for some time, but I would definitely encourage users to move to Python 3 sooner rather than later. To that end, I envision that soon Sage will have Python 2 and Python 3 binary releases, with some emphasis on getting people to use the latter. To that end it will be good to help as much as possible with transitioning. That said, there's also a question of when to switch the default in the docs over. If the docs are Python 3 then I think there should be no In other words, I'd be willing to change it, but it depends a lot on bigger plans regarding how Sage will transition to Python 3 that aren't particularly settled. But I feel right now that this currently with an eye toward being as helpful as possible for transitioning. |
comment:8
Replying to @embray:
Then it should be the same in doctests too. I'm fine with a deprecation or no deprecation either way, but I am protesting the condition on |
comment:9
I don't know why. It seems to me the whole point of having That said, I took a step back from this and rethought it a bit. I thought of adding a So maybe adding this helper isn't that useful anyways. So what if we only injected it into the globals when running the doctests, just temporarily, no deprecation warning or anything. Later, when we want to start moving the tests to be more Python 3-compatible, we just remove it and get NameErrors everywhere the tests try to use it. |
comment:10
OK, I'll stop fighting here. I don't really agree, but if you want to add |
comment:11
Thanks--though what do you think about my other proposal of just injecting I understand your feeling that the doctests should reflect what a real user sees. The problem with Sage is that the only tests (with a few exceptions) are the doctests. And for the purposes of porting to Python 3 I don't think that philosophy really applies. It's more important just that the tests are passing so that we can narrow down on real bugs (until we make Python 3 the default, in which case yes we don't want to special case anything in the doctests if possible). |
comment:12
Replying to @embray:
Go for it. |
Changed dependencies from #24258 to none |
comment:14
Why needs work? Th recent patchbot failures on this ticket are all a joke--they're broken patchbots. This one passed with the current branch on this ticket, and isn't a broken patchbot: https://patchbot.sagemath.org/log/24559/Ubuntu/16.04/x86_64/3.13.0-123-generic/sagemath-patchbot-docker/2018-02-04%2014:11:23 |
comment:15
Ignore me--I did do the proposed work, but it seems I haven't pushed it to the upstream branch yet... |
Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:
|
Dependencies: #24343 |
comment:17
This depends on #24343, but the new approach to handling Now, instead of providing a user-visible replacement for
|
Changed branch from u/embray/python3/long-literals to u/jdemeyer/python3/long-literals |
comment:20
Rebased New commits:
|
comment:21
Jeroen, I see you rebased this, but does that constitute a "review"? IIRC, the only open question on this ticket had to do with my plan for aliasing My experience with testing this, so far, has been that it allows a lot of tests to pass on Python 3 that wouldn't otherwise, with few exceptions, and that it's a decent transitional approach. The |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:24
I don't like this syntax:
It looks too much like a docstring but it isn't. Use a |
comment:25
That's standard syntax in Sphinx for documenting class attributes. |
comment:26
Replying to @embray:
According to the Sphinx documentation, Sphinx autodoc also supports the special comment syntax You may think that there is no harm in using strings-which-are-not-docstrings like that, but the problem is that it teaches a bad habit. In particular the following does not contain a doctest despite looking like it does:
|
Reviewer: Jeroen Demeyer |
comment:28
I don't think it's a bad habit. It's perfectly acceptable syntax and I think preferable from the Sphinx perspective over the special comment syntax. If there were a notion in the Python language of attaching a docstring to a particular class attribute that's probably how I'd write it (unfortunately the concept doesn't quite fit in with how the language works, though personally I can think of ways Python might use it). I think your concern is more a peculiarity of Sage, which overemphasizes doctests in the first place (or, perhaps if this really a problem, the doctest parser should be modified to look in triple-quoted strings anywhere in a class or module body--I think that might make sense anyways). |
Changed branch from u/jdemeyer/python3/long-literals to |
This does three little things to better support
long
-related functionality, especially in the doctests. This allows a lot of tests to pass on Python 3 that wouldn't otherwise, or would need to be skipped and/or have Python 3 specific copies:The Sage preparser supports Python 2 style long literals, like
42L
. These are just treated as normal ints on Python 3 (we could also consider adding a deprecation warning for this usage). I actually wish Python itself had done this (just as they restored backwards-compat foru''
literals--that they didn't I think is just that explicitlong
s is relatively uncommon.The doctest parser has a fixup for recognizing long literals in the expected output of a test, and treating them as normal ints on Python 3. This is probably the weakest part of the patch in terms of implementation--it's very naïve and I can imagine the possibility of false positives, though it is still pretty unlikely. Open to better ideas on this.
In
sage.all
I added, on Python 3 only, a new global calledlong
which is just a function that wrapsint()
and (except in the tests, for now) raises aDeprecationWarning
for usinglong()
. This still allows a lot of tests to work. I deliberately made it a simple function, and not a class, as the latter would tempt too many errors with code likeisinstance(x, long)
.Component: python3
Author: Erik Bray
Branch/Commit:
e3b8148
Reviewer: Jeroen Demeyer
Issue created by migration from https://trac.sagemath.org/ticket/24559
The text was updated successfully, but these errors were encountered: