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

Add a standard constructor for dynamic classes #5991

Closed
nthiery opened this issue May 5, 2009 · 24 comments
Closed

Add a standard constructor for dynamic classes #5991

nthiery opened this issue May 5, 2009 · 24 comments

Comments

@nthiery
Copy link
Contributor

nthiery commented May 5, 2009

This patch implements sage.structure.dynamic_class.dynamic_class, for constructing dynamically new python classes. The constructed classes can be pickled, and have unique representation.

The patch includes a discussion on the relevance of dynamic classes for Sage.

Depends on #5985 for pickling and #5120.

Used by the upcoming category framework #5891, (and sage-words?)

Issue: is sage.structure.dynamic_class.dynamic_class the natural location for this?

CC: @sagetrac-sage-combinat @saliola @roed314

Component: misc

Keywords: dynamic classes, unique representation

Author: Nicolas M. Thiéry

Reviewer: David Roe

Merged: sage-4.2.alpha0

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

@nthiery nthiery added this to the sage-4.2 milestone May 5, 2009
@nthiery nthiery self-assigned this May 5, 2009
@nthiery nthiery changed the title Add as tandard constructor for dynamic classes Add a standard constructor for dynamic classes May 5, 2009
@nthiery

This comment has been minimized.

@nthiery

This comment has been minimized.

@nthiery
Copy link
Contributor Author

nthiery commented May 8, 2009

comment:4

Patch updated for new version of #5120
Please ignore dynamic_class-5991-submitted.2.patch

@robertwb

This comment has been minimized.

@nthiery
Copy link
Contributor Author

nthiery commented May 21, 2009

Attachment: dynamic_class-5991-submitted.patch.gz

@roed314
Copy link
Contributor

roed314 commented May 21, 2009

comment:7

Looks good. Doctests pass.

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 13, 2009

Author: Nicolas Thiery

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 13, 2009

comment:8

Since this depends on #5985 which does not have a positive review it will have to wait.

@ncalexan
Copy link
Mannequin

ncalexan mannequin commented Jun 13, 2009

Reviewer: David Roe

@boothby
Copy link
Contributor

boothby commented Jun 24, 2009

comment:9

Doctest failures:

sage -t -long devel/sage/sage/structure/dynamic_class.py
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/dynamic_class.py", line 210:
    sage: loads(dumps(BarFoo))
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_1[23]>", line 1, in <module>
        loads(dumps(BarFoo))###line 210:
    sage: loads(dumps(BarFoo))
      File "sage_object.pyx", line 604, in sage.structure.sage_object.dumps (sage/structure/sage_ob$
        return comp.compress(cPickle.dumps(obj, protocol=2))
    PicklingError: Can't pickle <class '__main__.BarFoo'>: attribute lookup __main__.BarFoo failed
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/dynamic_class.py", line 224:
    sage: import sage.misc.cPickle as cPickle
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_1[30]>", line 1, in <module>
        import sage.misc.cPickle as cPickle###line 224:
    sage: import sage.misc.cPickle as cPickle
    ImportError: No module named cPickle
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/dynamic_class.py", line 225:
    sage: cPickle.loads(cPickle.dumps(FooBar)) == FooBar
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_1[31]>", line 1, in <module>
        cPickle.loads(cPickle.dumps(FooBar)) == FooBar###line 225:
    sage: cPickle.loads(cPickle.dumps(FooBar)) == FooBar
    NameError: name 'cPickle' is not defined
**********************************************************************
File "/space/boothby/sage-4.0.3/devel/sage-main/sage/structure/dynamic_class.py", line 238:
    sage: loads(dumps(FooUnique)) is FooUnique
Exception raised:
    Traceback (most recent call last):
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/space/boothby/sage-4.0.3/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_1[35]>", line 1, in <module>
        loads(dumps(FooUnique)) is FooUnique###line 238:
    sage: loads(dumps(FooUnique)) is FooUnique
      File "sage_object.pyx", line 604, in sage.structure.sage_object.dumps (sage/structure/sage_ob$
        return comp.compress(cPickle.dumps(obj, protocol=2))
    PicklingError: Can't pickle <class '__main__.Foo'>: it's not the same object as __main__.Foo
**********************************************************************
1 items had failures:
   4 of  36 in __main__.example_1
***Test Failed*** 4 failures.

@nthiery
Copy link
Contributor Author

nthiery commented Jun 24, 2009

comment:10

Yeah: it depends on #5985, but otherwise is ready.

Should there be a new field in the trac server for listing systematically the other tickets the ticket depends on?

@nthiery
Copy link
Contributor Author

nthiery commented Jul 10, 2009

comment:11

Attachment: trac_5991-dynamic_class-referee-dr.patch.gz

The two added patches, by David and myself improve introspection.
I give a positive review on David's. David, can you double check mine?

@nthiery
Copy link
Contributor Author

nthiery commented Jul 10, 2009

Changed author from Nicolas Thiery to Nicolas M. Thiéry

@nthiery
Copy link
Contributor Author

nthiery commented Jul 13, 2009

comment:12

Attachment: trac_5991-dynamic_class-referee-nt.patch.gz

Replying to @nthiery:

The two added patches, by David and myself improve introspection.
I give a positive review on David's. David, can you double check mine?

The updated referee patch by myself adds a copyright header, and fixes a warning in sage -docbuild.

David: please double check!

@nthiery
Copy link
Contributor Author

nthiery commented Jul 17, 2009

Attachment: dynamic_class-reduction-nt.patch.gz

Fix reduction after David's referee patch

@nthiery
Copy link
Contributor Author

nthiery commented Jul 17, 2009

Fold of all the patches above. Apply only this one

@nthiery
Copy link
Contributor Author

nthiery commented Jul 17, 2009

comment:13

Attachment: trac_5991_dynamic_class-nt.patch.gz

David: can you have a quick look at my latest addition, and set a positive review (pending #5985)

@roed314
Copy link
Contributor

roed314 commented Jul 18, 2009

comment:14

So, I approve the changes. I don't have time right now to run doctests though: the release manager (or someone) should make sure to do so.

@nthiery
Copy link
Contributor Author

nthiery commented Jul 18, 2009

comment:15

Replying to @roed314:

So, I approve the changes. I don't have time right now to run doctests though: the release manager (or someone) should make sure to do so.

Thanks! All the doctest pass on my machine, but yes, a triple check would be good.

@nthiery
Copy link
Contributor Author

nthiery commented Oct 11, 2009

comment:16

If #5985 is ready on time to get integrated in 4.1.2, it would be great to have this on go in too.

@nthiery nthiery modified the milestones: sage-4.2, sage-4.1.2 Oct 11, 2009
@williamstein
Copy link
Contributor

comment:17

NOTE to self -- the change to sageinspect needs to be ported into the separated notebook when this is merged.

@mwhansen
Copy link
Contributor

Attachment: trac_5991_dynamic_class-nt.2.patch.gz

@mwhansen
Copy link
Contributor

Merged: sage-4.2.alpha0

@mwhansen
Copy link
Contributor

comment:18

I had to make the change to the way cPickle is imported as in #5985. I'll make a new ticket for sageinspect in the separated notebook.

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

6 participants