133133addition_names = ('addition' , 'plus' , 'sum' , '+' )
134134
135135
136- def _parse_group_def (parent , operation , identity , inverse , op , * , check_missing = True ):
136+ def _parse_group_def (parent , operation , identity , inverse , op , * , check = True ):
137137 """
138138 Helper function to parse the user input for group operations.
139139 Only two possibilities are accepted:
@@ -156,6 +156,10 @@ def _parse_group_def(parent, operation, identity, inverse, op, *, check_missing=
156156 returning its inverse
157157 - ``op`` -- if not ``None``, a function taking two arguments and
158158 computing the group operation on these two arguments
159+ - ``check`` -- boolean (default: ``True``); ensure that everything are specified.
160+ The caller may choose to pass ``check=False`` if it only need some of the
161+ group operations, for example, :func:`multiple` wouldn't need ``inverse`` and
162+ ``identity`` if the exponent is positive.
159163
160164 OUTPUT: a tuple ``('other', identity, inverse, op)``
161165
@@ -191,7 +195,7 @@ def _parse_group_def(parent, operation, identity, inverse, op, *, check_missing=
191195 try :
192196 identity = parent .one ()
193197 except Exception :
194- if check_missing :
198+ if check :
195199 raise
196200 inverse = inv
197201 op = mul
@@ -202,12 +206,12 @@ def _parse_group_def(parent, operation, identity, inverse, op, *, check_missing=
202206 try :
203207 identity = parent .zero ()
204208 except Exception :
205- if check_missing :
209+ if check :
206210 raise
207211 inverse = neg
208212 op = add
209213 else :
210- if check_missing and (identity is None or inverse is None or op is None ):
214+ if check and (identity is None or inverse is None or op is None ):
211215 raise ValueError ("identity, inverse and operation must all be specified "
212216 "when operation is neither addition nor multiplication" )
213217 return 'other' , identity , inverse , op
0 commit comments