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

ElementWrapper: A class for wrapping Sage or Python objects as Sage elements #5967

Closed
nthiery opened this issue May 3, 2009 · 18 comments
Closed

Comments

@nthiery
Copy link
Contributor

nthiery commented May 3, 2009

This patch implements a simple class ElementWrapper for wrapping Sage
or Python objects as Sage elements, with reasonable default
implementations of repr, cmp, hash, etc. The typical use case is for
trivially constructing new element classes from preexisting Sage or
Python classes, with a containment relation.

This class is used extensively in the examples of the upcoming category framework patch #5891.

CC: @sagetrac-sage-combinat

Component: misc

Author: Nicolas M. Thiéry

Reviewer: Anne Schilling, Robert Bradshaw

Merged: 4.0.1.alpha0

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

@nthiery nthiery added this to the sage-4.0.1 milestone May 3, 2009
@nthiery nthiery self-assigned this May 3, 2009
@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented May 3, 2009

comment:1

This is broken:

 	129	            sage: cmp(l11, l12), cmp(l12, l11)   # values differ 
 	130	            (-1, 1) 
 	131	            sage: cmp(l11, l21), cmp(l21, l11)   # parents differ 
 	132	            (-1, 1) 

Never check the return value of cmp to be -1 or 1, but always write

sage: cmp(l11, l21) in [-1,1]
True

since the value depends on memory location. I have had to fix this literally dozens of times in doctests.

Cheers,

Michael

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented May 3, 2009

comment:2

This ticket also needs to be properly market with a marker so it is picked up for review.

Another thing to fix is to get this file into the documentation. Unless it is in the documentation the vast majority of people will never know of its existence. Current policy is that every file that is well documented and 100% doctested belongs in the documentation.

Cheers,

Michael

@nthiery
Copy link
Contributor Author

nthiery commented May 3, 2009

comment:3

Replying to @sagetrac-mabshoff:

This is broken:

 	129	            sage: cmp(l11, l12), cmp(l12, l11)   # values differ 
 	130	            (-1, 1) 
 	131	            sage: cmp(l11, l21), cmp(l21, l11)   # parents differ 
 	132	            (-1, 1) 

Never check the return value of cmp to be -1 or 1, but always write

sage: cmp(l11, l21) in [-1,1]
True

since the value depends on memory location. I have had to fix this literally dozens of times in doctests.

Ok, will do.

@nthiery
Copy link
Contributor Author

nthiery commented May 3, 2009

comment:4

Replying to @sagetrac-mabshoff:

This ticket also needs to be properly market with a marker so it is picked up for review.

Any suggestion for that marker?

Another thing to fix is to get this file into the documentation. Unless it is in the documentation the vast majority of people will never know of its existence. Current policy is that every file that is well documented and 100% doctested belongs in the documentation.

Ok, will do.

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented May 3, 2009

comment:5

Replying to @nthiery:

Replying to @sagetrac-mabshoff:

This ticket also needs to be properly market with a marker so it is picked up for review.

Any suggestion for that marker?

I meant the standard "[with patch, needs review]" :)

Cheers,

Michael

@nthiery
Copy link
Contributor Author

nthiery commented May 3, 2009

comment:6

Replying to @sagetrac-mabshoff:

I meant the standard "[with patch, needs review]" :)

Oops, I was sure I had done this!

@nthiery
Copy link
Contributor Author

nthiery commented May 3, 2009

comment:7

Done, and patch updated. Thanks Michael for your suggestions.

@anneschilling
Copy link

comment:8

The tests of the patch pass when applied to sage-3.4.2.

Besides the application to the category framework #5891,
this patch will be useful for crystals. For example the
class Letter(Element):
in /combinat/crystals/letters.py
can be shortened by inheriting from ElementWrapper.

I give this patch a positive review!

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented May 22, 2009

comment:10

Has anybody non-combinat signed off on this? Not that I don't trust Anne, but ... ;)

Cheers,

Michael

@nthiery
Copy link
Contributor Author

nthiery commented May 23, 2009

comment:11

The uploaded patch adds a warning about the probable little change of interface in the near future (but after integration of the category patch).
Robert promised to have a look at this shortly.

@robertwb
Copy link
Contributor

comment:12

I agree this looks good. The only caveat is that the docstring reads

Therefore, ``o`` does inherit the string

where it probably should be "does not."

@nthiery
Copy link
Contributor Author

nthiery commented May 23, 2009

Attachment: element_wrapper-5967-submitted.patch.gz

@nthiery
Copy link
Contributor Author

nthiery commented May 23, 2009

comment:13

Replying to @robertwb:

I agree this looks good. The only caveat is that the docstring reads

Therefore, ``o`` does inherit the string

where it probably should be "does not."

Oops, indeed! Thanks. Patch updated.

@mwhansen
Copy link
Contributor

comment:14

Merged in 4.0.1.alpha0.

@mwhansen
Copy link
Contributor

mwhansen commented Jun 6, 2009

Reviewer: Anne Schilling, Robert Bradshaw

@mwhansen
Copy link
Contributor

mwhansen commented Jun 6, 2009

Author: Nicolas Thiery

@mwhansen
Copy link
Contributor

mwhansen commented Jun 6, 2009

Merged: 4.0.1.alpha0

@fchapoton
Copy link
Contributor

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

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