(data, *, precision, floatmode, suppress, sign, legacy,
formatter, **kwargs)
| 401 | return str(x) |
| 402 | |
| 403 | def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy, |
| 404 | formatter, **kwargs): |
| 405 | # note: extra arguments in kwargs are ignored |
| 406 | |
| 407 | # wrapped in lambdas to avoid taking a code path with the wrong type of data |
| 408 | formatdict = { |
| 409 | 'bool': lambda: BoolFormat(data), |
| 410 | 'int': lambda: IntegerFormat(data), |
| 411 | 'float': lambda: FloatingFormat( |
| 412 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 413 | 'longfloat': lambda: FloatingFormat( |
| 414 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 415 | 'complexfloat': lambda: ComplexFloatingFormat( |
| 416 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 417 | 'longcomplexfloat': lambda: ComplexFloatingFormat( |
| 418 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 419 | 'datetime': lambda: DatetimeFormat(data, legacy=legacy), |
| 420 | 'timedelta': lambda: TimedeltaFormat(data), |
| 421 | 'object': lambda: _object_format, |
| 422 | 'void': lambda: str_format, |
| 423 | 'numpystr': lambda: repr_format} |
| 424 | |
| 425 | # we need to wrap values in `formatter` in a lambda, so that the interface |
| 426 | # is the same as the above values. |
| 427 | def indirect(x): |
| 428 | return lambda: x |
| 429 | |
| 430 | if formatter is not None: |
| 431 | fkeys = [k for k in formatter.keys() if formatter[k] is not None] |
| 432 | if 'all' in fkeys: |
| 433 | for key in formatdict.keys(): |
| 434 | formatdict[key] = indirect(formatter['all']) |
| 435 | if 'int_kind' in fkeys: |
| 436 | for key in ['int']: |
| 437 | formatdict[key] = indirect(formatter['int_kind']) |
| 438 | if 'float_kind' in fkeys: |
| 439 | for key in ['float', 'longfloat']: |
| 440 | formatdict[key] = indirect(formatter['float_kind']) |
| 441 | if 'complex_kind' in fkeys: |
| 442 | for key in ['complexfloat', 'longcomplexfloat']: |
| 443 | formatdict[key] = indirect(formatter['complex_kind']) |
| 444 | if 'str_kind' in fkeys: |
| 445 | formatdict['numpystr'] = indirect(formatter['str_kind']) |
| 446 | for key in formatdict.keys(): |
| 447 | if key in fkeys: |
| 448 | formatdict[key] = indirect(formatter[key]) |
| 449 | |
| 450 | return formatdict |
| 451 | |
| 452 | def _get_format_function(data, **options): |
| 453 | """ |
no test coverage detected