(data, *, precision, floatmode, suppress, sign, legacy,
formatter, **kwargs)
| 474 | return str(x) |
| 475 | |
| 476 | def _get_formatdict(data, *, precision, floatmode, suppress, sign, legacy, |
| 477 | formatter, **kwargs): |
| 478 | # note: extra arguments in kwargs are ignored |
| 479 | |
| 480 | # wrapped in lambdas to avoid taking a code path |
| 481 | # with the wrong type of data |
| 482 | formatdict = { |
| 483 | 'bool': lambda: BoolFormat(data), |
| 484 | 'int': lambda: IntegerFormat(data, sign), |
| 485 | 'float': lambda: FloatingFormat( |
| 486 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 487 | 'longfloat': lambda: FloatingFormat( |
| 488 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 489 | 'complexfloat': lambda: ComplexFloatingFormat( |
| 490 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 491 | 'longcomplexfloat': lambda: ComplexFloatingFormat( |
| 492 | data, precision, floatmode, suppress, sign, legacy=legacy), |
| 493 | 'datetime': lambda: DatetimeFormat(data, legacy=legacy), |
| 494 | 'timedelta': lambda: TimedeltaFormat(data), |
| 495 | 'object': lambda: _object_format, |
| 496 | 'void': lambda: str_format, |
| 497 | 'numpystr': lambda: repr_format} |
| 498 | |
| 499 | # we need to wrap values in `formatter` in a lambda, so that the interface |
| 500 | # is the same as the above values. |
| 501 | def indirect(x): |
| 502 | return lambda: x |
| 503 | |
| 504 | if formatter is not None: |
| 505 | fkeys = [k for k in formatter.keys() if formatter[k] is not None] |
| 506 | if 'all' in fkeys: |
| 507 | for key in formatdict.keys(): |
| 508 | formatdict[key] = indirect(formatter['all']) |
| 509 | if 'int_kind' in fkeys: |
| 510 | for key in ['int']: |
| 511 | formatdict[key] = indirect(formatter['int_kind']) |
| 512 | if 'float_kind' in fkeys: |
| 513 | for key in ['float', 'longfloat']: |
| 514 | formatdict[key] = indirect(formatter['float_kind']) |
| 515 | if 'complex_kind' in fkeys: |
| 516 | for key in ['complexfloat', 'longcomplexfloat']: |
| 517 | formatdict[key] = indirect(formatter['complex_kind']) |
| 518 | if 'str_kind' in fkeys: |
| 519 | formatdict['numpystr'] = indirect(formatter['str_kind']) |
| 520 | for key in formatdict.keys(): |
| 521 | if key in fkeys: |
| 522 | formatdict[key] = indirect(formatter[key]) |
| 523 | |
| 524 | return formatdict |
| 525 | |
| 526 | def _get_format_function(data, **options): |
| 527 | """ |
no test coverage detected
searching dependent graphs…