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

Remove some py2 tags in explain_pickle #33144

Closed
fchapoton opened this issue Jan 10, 2022 · 36 comments
Closed

Remove some py2 tags in explain_pickle #33144

fchapoton opened this issue Jan 10, 2022 · 36 comments

Comments

@fchapoton
Copy link
Contributor

We remove some py2 tags from explain_pickle doctests which we still get correct results (with python3).

CC: @embray @mjungmath @tscrim

Component: python3

Author: Frédéric Chapoton

Branch/Commit: 131841f

Reviewer: Travis Scrimshaw, Kwankyu Lee

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

@fchapoton fchapoton added this to the sage-9.5 milestone Jan 10, 2022
@fchapoton
Copy link
Contributor Author

Branch: u/chapoton/33144

@fchapoton
Copy link
Contributor Author

Commit: 9d0b7a1

@fchapoton
Copy link
Contributor Author

comment:1

boring and painful update..

any expert on pickles aboard ?


New commits:

9d0b7a1removal of py2 tag in doctests of explain pickle (first wave)

@fchapoton
Copy link
Contributor Author

comment:3

ok, let's do that in several steps. Please review this first step.

@fchapoton
Copy link
Contributor Author

comment:6

please somebody have a look

This is the last file containing #py2 tags. Here I remove only the simple ones, and the changes should rather be uncontroversial. The remaining cases are out of my capacity, and require an expert of pickle, that we may no longer have anywhere in sight..

One alternative would be #27350 (externalize) or just drop the file completely.

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:7

It would be wonderful for Erik Bray to work on #27350 and close this ticket as invalid/wontfix.

If that would not happen, then I think we should fix explain_pickle for python3 before we remove the py2 tag, instead of "fixing" doctests for the broken explain_pickle.

@fchapoton
Copy link
Contributor Author

comment:8

As far as I understand, Erik is no longer available.

@tscrim
Copy link
Collaborator

tscrim commented Jun 14, 2022

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Jun 14, 2022

comment:9

In principle, I agree with #27350, but I am slightly worried about the practice of it since I find this tool to be very useful at times and would be saddened if it bitrotted. I, unfortunately, would not be able to maintain such a package as I don't understand how explain_pickle() works. Since these doctests seem to just be updating the output, I think we should merge these in now. Likewise, I don't think I could help with any of the further marked tests.

Kwankyu, any objections to me setting a positive review?

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:10

Replying to @tscrim:

Since these doctests seem to just be updating the output,

Some outputs from explain_pickle (via test_pickle), for instance,

             sage: from sage.misc.explain_pickle import *
-            sage: test_pickle(dumps(100000r, compress=False))  # py2
-                0: \x80 PROTO      2
-                2: J    BININT     100000
-                7: .    STOP
-            highest protocol among opcodes = 2
-            explain_pickle in_current_sage=True/False:
-            100000
-            result: 100000
+            sage: test_pickle(dumps(100000r, compress=False))
+                    0: \x80 PROTO      2
+                    2: c    GLOBAL     '_codecs encode'
+                   18: q    BINPUT     0
+                   20: X    BINUNICODE '\x80\x02J\xa0\x86\x01\x00.'
+                   36: q    BINPUT     1
+                   38: X    BINUNICODE 'latin1'
+                   49: q    BINPUT     2
+                   51: \x86 TUPLE2
+                   52: q    BINPUT     3
+                   54: R    REDUCE
+                   55: q    BINPUT     4
+                   57: .    STOP
+                highest protocol among opcodes = 2
+                explain_pickle in_current_sage=True:
+                from _codecs import encode
+                encode('\x80\x02J\xa0\x86\x01\x00.', 'latin1')
+                explain_pickle in_current_sage=False:
+                pg_encode = unpickle_global('_codecs', 'encode')
+                pg_encode('\x80\x02J\xa0\x86\x01\x00.', 'latin1')
+                result: b'\x80\x02J\xa0\x86\x01\x00.'

seem wrong, which indicates it worked fine with py2 but is now broken with py3. Do we ever correct doctests for wrong output? I think leaving them with py2 tag is right if we do not fix the broken explain_pickle.

Indentations of outputs are wrong.

@tscrim
Copy link
Collaborator

tscrim commented Jun 14, 2022

comment:11

Replying to @kwankyu:

Replying to @tscrim:

Since these doctests seem to just be updating the output,

seem wrong, which indicates it worked fine with py2 but is now broken with py3. Do we ever correct doctests for wrong output? I think leaving them with py2 tag is right if we do not fix the broken explain_pickle.

The pickle itself has changed. If you run loads(dumps(100000r)), it returns the correct object without error. In this case, it is likely because int has changed from Python2 to Python3.

Indentations of outputs are wrong.

Indeed; although I found the extra indentation level helped make clear what the doctest outputs were since they are so long with their own indentation. I don't hold a strong opinion on changing this or not.

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:12

Replying to @tscrim:

Replying to @kwankyu:

Replying to @tscrim:

Since these doctests seem to just be updating the output,

seem wrong, which indicates it worked fine with py2 but is now broken with py3. Do we ever correct doctests for wrong output? I think leaving them with py2 tag is right if we do not fix the broken explain_pickle.

The pickle itself has changed.

I meant the result. Shouldn't it be 100000?

@tscrim
Copy link
Collaborator

tscrim commented Jun 14, 2022

comment:13

Replying to @kwankyu:

Replying to @tscrim:

Replying to @kwankyu:

Replying to @tscrim:

Since these doctests seem to just be updating the output,

seem wrong, which indicates it worked fine with py2 but is now broken with py3. Do we ever correct doctests for wrong output? I think leaving them with py2 tag is right if we do not fix the broken explain_pickle.

The pickle itself has changed.

I meant the result. Shouldn't it be 100000?

I believe it is the right result but represented or interpreted in the wrong format. Mainly the bytes returned are not converted to a string correctly or something similar.

@tscrim
Copy link
Collaborator

tscrim commented Jun 14, 2022

comment:14

Perhaps we just don't remove the tag in the cases when the result is (at least superficially) different?

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:15

Replying to @tscrim:

Perhaps we just don't remove the tag in the cases when the result is (at least superficially) different?

+1

@fchapoton
Copy link
Contributor Author

Changed branch from u/chapoton/33144 to public/ticket/33144-short

@fchapoton
Copy link
Contributor Author

comment:16

here is a new branch, where I have dropped the changes that did no look right

I may have missed some


New commits:

cf9a6d9remove only some simple #py2 tags in explain_pickle

@fchapoton
Copy link
Contributor Author

Changed commit from 9d0b7a1 to cf9a6d9

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:17

How about indentations? Did you indent more spaces intentionally?

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 14, 2022

comment:18

I think outputs should look as they do on the command line, modulo wrappings.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 15, 2022

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

3c82b13remove some #py2 tags in explain_pickle

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 15, 2022

Changed commit from cf9a6d9 to 3c82b13

@fchapoton
Copy link
Contributor Author

comment:20

now the same as previous one, only with less indentations

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 15, 2022

comment:21

Thanks. But some cases with different result are still in.

@fchapoton
Copy link
Contributor Author

patch for removing some #py2 tags

@fchapoton
Copy link
Contributor Author

comment:22

Attachment: 0001-removal-of-py2-tag-in-doctests-of-explain-pickle-fir.patch.gz

Then maybe the simplest way would be if you could please edit the attached patch file : keep only the changes that you find appropriate and make a branch from that modified patch.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2022

Changed commit from 3c82b13 to 131841f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 26, 2022

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

b47176eMerge branch 'develop'
131841fRestore py2 tag for cases with different result

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 26, 2022

comment:24

Replying to @fchapoton:

Then maybe the simplest way would be if you could please edit the attached patch file : keep only the changes that you find appropriate and make a branch from that modified patch.

That is done over your last commit.

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 26, 2022

Changed reviewer from Travis Scrimshaw to Travis Scrimshaw, Kwankyu Lee

@kwankyu

This comment has been minimized.

@kwankyu
Copy link
Collaborator

kwankyu commented Jun 26, 2022

comment:25

I am positive now.

@kwankyu kwankyu changed the title remove py2 tags in explain_pickle Remove py2 tags in explain_pickle Jun 26, 2022
@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor Author

comment:26

thanks, you can set to positive if you wish

@fchapoton fchapoton changed the title Remove py2 tags in explain_pickle Remove some py2 tags in explain_pickle Jun 26, 2022
@kwankyu
Copy link
Collaborator

kwankyu commented Jun 27, 2022

comment:27

Thanks.

@vbraun
Copy link
Member

vbraun commented Jul 9, 2022

Changed branch from public/ticket/33144-short to 131841f

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

5 participants