MCPcopy Index your code
hub / github.com/python/cpython / __format__

Method __format__

Lib/fractions.py:599–614  ·  view source on GitHub ↗

Format this fraction according to the given format specification.

(self, format_spec, /)

Source from the content-addressed store, hash-verified

597 return sign + padding + body
598
599 def __format__(self, format_spec, /):
600 """Format this fraction according to the given format specification."""
601
602 if match := _GENERAL_FORMAT_SPECIFICATION_MATCHER(format_spec):
603 return self._format_general(match)
604
605 if match := _FLOAT_FORMAT_SPECIFICATION_MATCHER(format_spec):
606 # Refuse the temptation to guess if both alignment _and_
607 # zero padding are specified.
608 if match["align"] is None or match["zeropad"] is None:
609 return self._format_float_style(match)
610
611 raise ValueError(
612 f"Invalid format specifier {format_spec!r} "
613 f"for object of type {type(self).__name__!r}"
614 )
615
616 def _operator_fallbacks(monomorphic_operator, fallback_operator,
617 handle_complex=True):

Callers

nothing calls this directly

Calls 2

_format_generalMethod · 0.95
_format_float_styleMethod · 0.95

Tested by

no test coverage detected