Opened 9 years ago

Closed 9 years ago

#12788 closed enhancement (fixed)

Provide Integer class with a __format__ method

Reported by: nbruin Owned by: AlexGhitza
Priority: trivial Milestone: sage-5.0
Component: basic arithmetic Keywords:
Cc: Merged in: sage-5.0.beta12
Authors: Nils Bruin Reviewers: Mike Hansen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


It was observed in this sage-support thread that Python new-style format specifiers for Sage Integers don't work. The solution is easy: Equip Integer with a __format__ method that simply converts the Sage Integer to a Python int and then calls the __format__ method on that. Given that converting a GMP int to a Python int should be much cheaper than converting either to a string, I don't expect much of a performance penalty, and implementing the whole Format mini-language again seems a waste of effort.

Attachments (1)

12788.patch (989 bytes) - added by nbruin 9 years ago.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by nbruin

comment:1 Changed 9 years ago by nbruin

  • Authors set to Nils Bruin
  • Status changed from new to needs_review

comment:2 Changed 9 years ago by mhansen

  • Reviewers set to Mike Hansen
  • Status changed from needs_review to positive_review

Looks good to me.

comment:3 Changed 9 years ago by jdemeyer

  • Merged in set to sage-5.0.beta12
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.