Glitches in f-strings support

Issue #91 resolved
Pierre Denis repo owner created an issue

Probabilities put in f-strings do not take into account the Lea’s display options.

set_display_options(kind='%', nb_decimals=2)
print (P(event(1/3)))
# -> 33.33 %
print (f"{P(event(1/3))}")
# -> 0.333333333333333314829616256247390992939472198486328125

This is because Lea class (4.0.0) does not implement the __format__ method, which is called for f-strings.

Also, for probability distributions, the multiline format is not very adequate:

print(f"The probability distribution is {event(1/3)}")
# -> The probability distribution is False :  66.67 %
     True  :  33.33 %

It would be more sensible to switch to one-line format in such case:

 The probability distribution is { False:  66.67 %, True:  33.33 % }

All these small glitches can be fixed easily by implementing the Lea.__format__ method.

Comments (3)

  1. Log in to comment