# HG changeset patch
# User Travis Scrimshaw <tscrim@ucdavis.edu>
# Date 1360990290 28800
# Node ID 36485e4d0efd65645ce0405f4dadd0e66bbf4efb
# Parent 6fd86fa95cdaa12dd489c25d6c6554ecf139a351
Trac #13688  Allow finite sets cardinality to handle optional args.
diff git a/sage/categories/finite_enumerated_sets.py b/sage/categories/finite_enumerated_sets.py
a

b

class FiniteEnumeratedSets(Category): 
96  96  """ 
97  97  return True 
98  98  
99   def _cardinality_from_iterator(self): 
 99  def _cardinality_from_iterator(self, *ignored_args, **ignored_kwds): 
100  100  """ 
101  101  The cardinality of ``self``. 
102  102  
… 
… 
class FiniteEnumeratedSets(Category): 
125  125  TESTS: 
126  126  
127  127  This method shall return an ``Integer``; we test this 
128   here, because :meth:'_test_enumerated_set_iter_cardinality' 
 128  here, because :meth:`_test_enumerated_set_iter_cardinality` 
129  129  does not do it for us:: 
130  130  
131  131  sage: type(C._cardinality_from_iterator()) 
132  132  <type 'sage.rings.integer.Integer'> 
 133  
 134  We ignore additional inputs since during doctests classes which 
 135  override ``cardinality()`` call up to the category rather than 
 136  their own ``cardinality()`` method (see :trac:`13688`):: 
 137  
 138  sage: C = FiniteEnumeratedSets().example() 
 139  sage: C._cardinality_from_iterator(algorithm='testing') 
 140  3 
 141  
 142  Here is a more complete example:: 
 143  
 144  sage: class TestParent(Parent): 
 145  ... def __init__(self): 
 146  ... Parent.__init__(self, category=FiniteEnumeratedSets()) 
 147  ... def __iter__(self): 
 148  ... yield 1 
 149  ... return 
 150  ... def cardinality(self, dummy_arg): 
 151  ... return 1 # we don't want to change the semantics of cardinality() 
 152  sage: P = TestParent() 
 153  sage: P.cardinality(1) 
 154  1 
 155  sage: v = P.list(); v 
 156  [1] 
 157  sage: P.cardinality() 
 158  1 
 159  sage: P.cardinality('use alt algorithm') # Used to break here: see :trac:`13688` 
 160  1 
 161  sage: P.cardinality(dummy_arg='use alg algorithm') # Used to break here: see :trac:`13688` 
 162  1 
133  163  """ 
134  164  c = 0 
135  165  for _ in self: 
… 
… 
class FiniteEnumeratedSets(Category): 
156  186  """ 
157  187  return [x for x in self] 
158  188  
159   def _cardinality_from_list(self): 
 189  def _cardinality_from_list(self, *ignored_args, **ignored_kwds): 
160  190  """ 
161  191  The cardinality of ``self``. 
162  192  
… 
… 
class FiniteEnumeratedSets(Category): 
170  200  sage: C = FiniteEnumeratedSets().example() 
171  201  sage: C._cardinality_from_list() 
172  202  3 
 203  
 204  We ignore additional inputs since during doctests classes which 
 205  override ``cardinality()`` call up to the category rather than 
 206  their own ``cardinality()`` method (see :trac:`13688`):: 
 207  
 208  sage: C = FiniteEnumeratedSets().example() 
 209  sage: C._cardinality_from_list(algorithm='testing') 
 210  3 
173  211  """ 
174  212  # We access directly the cache self._list to bypass the 
175  213  # copy that self.list() currently does each time. 