Opened 3 years ago
Closed 3 years ago
#27390 closed enhancement (fixed)
Py3: test_class_pickling.py fix method resolution order error
Reported by: | vklein | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.7 |
Component: | python3 | Keywords: | |
Cc: | Merged in: | ||
Authors: | Vincent Klein | Reviewers: | Jeroen Demeyer |
Report Upstream: | N/A | Work issues: | |
Branch: | 6946310 (Commits, GitHub, GitLab) | Commit: | 6946310194a5407fa2e77a9241de5f51c3650b17 |
Dependencies: | Stopgaps: |
Description (last modified by )
Fix the
sage -t --long src/sage/misc/test_class_pickling.py ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 20, in sage.misc.test_class_pickling.metaclass Failed example: c = metaclass("foo2", (object, bar,)) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.metaclass[1]>", line 1, in <module> c = metaclass("foo2", (object, bar,)) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/misc/test_class_pickling.py", line 31, in metaclass result = Metaclass(name, bases, dict()) TypeError: Cannot create a consistent method resolution order (MRO) for bases object, bar **********************************************************************
errors in python3.
As bar
inherit from object
python3 is unable to define the method resolution order.
Add another test object and rewrite the doctests with this object.
This ticket fixes all python3 errors in test_class_pickling.py
Change History (16)
comment:1 Changed 3 years ago by
- Branch set to u/vklein/27390
comment:2 Changed 3 years ago by
- Commit set to 82f97c33db686d77a2dc0c8878151cafca380ce5
comment:3 Changed 3 years ago by
- Status changed from new to needs_review
comment:4 Changed 3 years ago by
- Status changed from needs_review to needs_info
It would be useful if you could post the actual errors that this ticket is supposed to fix.
comment:5 Changed 3 years ago by
- Status changed from needs_info to needs_review
Sure :
sage -t --long src/sage/misc/test_class_pickling.py too many failed tests, not using stored timings Running doctests with ID 2019-03-01-15-36-28-4c28d334. Git branch: develop Using --optional=dochtml,gmpy2,memlimit,mpir,python2,sage Doctesting 1 file. sage -t --long src/sage/misc/test_class_pickling.py ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 20, in sage.misc.test_class_pickling.metaclass Failed example: c = metaclass("foo2", (object, bar,)) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.metaclass[1]>", line 1, in <module> c = metaclass("foo2", (object, bar,)) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/misc/test_class_pickling.py", line 31, in metaclass result = Metaclass(name, bases, dict()) TypeError: Cannot create a consistent method resolution order (MRO) for bases object, bar ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 22, in sage.misc.test_class_pickling.metaclass Failed example: c Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.metaclass[2]>", line 1, in <module> c NameError: name 'c' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 24, in sage.misc.test_class_pickling.metaclass Failed example: type(c) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.metaclass[3]>", line 1, in <module> type(c) NameError: name 'c' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 26, in sage.misc.test_class_pickling.metaclass Failed example: c.__bases__ Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.metaclass[4]>", line 1, in <module> c.__bases__ NameError: name 'c' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 49, in sage.misc.test_class_pickling.Metaclass Failed example: c = metaclass("foo", (object, bar,)) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass[1]>", line 1, in <module> c = metaclass("foo", (object, bar,)) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/misc/test_class_pickling.py", line 31, in metaclass result = Metaclass(name, bases, dict()) TypeError: Cannot create a consistent method resolution order (MRO) for bases object, bar ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 52, in sage.misc.test_class_pickling.Metaclass Failed example: s = cPickle.dumps(c) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass[3]>", line 1, in <module> s = cPickle.dumps(c) NameError: name 'c' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 54, in sage.misc.test_class_pickling.Metaclass Failed example: c2 = cPickle.loads(s) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass[4]>", line 1, in <module> c2 = cPickle.loads(s) NameError: name 's' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 56, in sage.misc.test_class_pickling.Metaclass Failed example: c == c2 Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass[5]>", line 1, in <module> c == c2 NameError: name 'c' is not defined ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 72, in sage.misc.test_class_pickling.Metaclass.__reduce__ Failed example: c = metaclass("foo3", (object, bar,)) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass.__reduce__[1]>", line 1, in <module> c = metaclass("foo3", (object, bar,)) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/misc/test_class_pickling.py", line 31, in metaclass result = Metaclass(name, bases, dict()) TypeError: Cannot create a consistent method resolution order (MRO) for bases object, bar ********************************************************************** File "src/sage/misc/test_class_pickling.py", line 74, in sage.misc.test_class_pickling.Metaclass.__reduce__ Failed example: c.__class__.__reduce__(c) Exception raised: Traceback (most recent call last): File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/vklein/odk/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute exec(compiled, globs) File "<doctest sage.misc.test_class_pickling.Metaclass.__reduce__[2]>", line 1, in <module> c.__class__.__reduce__(c) NameError: name 'c' is not defined ********************************************************************** 3 items had failures: 4 of 7 in sage.misc.test_class_pickling.Metaclass 2 of 4 in sage.misc.test_class_pickling.Metaclass.__reduce__ 4 of 6 in sage.misc.test_class_pickling.metaclass [14 tests, 10 failures, 0.01 s] ---------------------------------------------------------------------- sage -t --long src/sage/misc/test_class_pickling.py # 10 doctests failed ---------------------------------------------------------------------- Total time for all tests: 0.0 seconds cpu time: 0.0 seconds cumulative wall time: 0.0 seconds
comment:6 Changed 3 years ago by
- Description modified (diff)
I don't understand why adding the class alpha
would fix anything.
comment:7 Changed 3 years ago by
It's not really about adding a class alpha
. The goal is just to have two classes with no inheritance relationship in order to do a successful call to the metaclass
function.
comment:8 Changed 3 years ago by
But why does it fail in Python 3 in the first place?
comment:9 follow-up: ↓ 10 Changed 3 years ago by
For me the question is more why it works in python2:
py2
>>> class a: ... pass ... >>> class b(object, a): ... pass ... >>> class c(a,b): ... pass ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases a, b
py3
>>> class a: ... pass ... >>> class b(object, a): ... pass ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Cannot create a consistent method resolution order (MRO) for bases a, object
Python3 looks more consistent to me.
comment:10 in reply to: ↑ 9 Changed 3 years ago by
Yes of course, I was confusing MRO errors with metaclass errors because I saw the word metaclass
in the code.
comment:11 Changed 3 years ago by
- Status changed from needs_review to needs_work
Since this doctests isn't about MROs, I think that a better and simpler solution would be to change the bases (object, bar)
to (bar, object)
.
comment:12 Changed 3 years ago by
Ok i will do that.
comment:13 Changed 3 years ago by
- Commit changed from 82f97c33db686d77a2dc0c8878151cafca380ce5 to 6946310194a5407fa2e77a9241de5f51c3650b17
Branch pushed to git repo; I updated commit sha1. New commits:
6946310 | Trac #27390: Implement a simpler solution.
|
comment:14 Changed 3 years ago by
- Status changed from needs_work to needs_review
comment:15 Changed 3 years ago by
- Reviewers set to Jeroen Demeyer
- Status changed from needs_review to positive_review
comment:16 Changed 3 years ago by
- Branch changed from u/vklein/27390 to 6946310194a5407fa2e77a9241de5f51c3650b17
- Resolution set to fixed
- Status changed from positive_review to closed
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
Trac #27390: Fix misc.test_class_pickling for py3