Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 651df81

Browse files
committed
Simplify backend_ps._nums_to_str.
_num_to_str is never used by itself and can be folded into the plural version. It is never called with a str argument so that check can be removed. Exact integer arguments can also be directly handled by the floating-point handling path (Technically, this will cause a rounding error for integers greater than `2**53`, but the PostScript standard only supports 32-bit integers anyways); the performance cost should be negligible (in fact, possibly more than compensated by the removal of the instance check in the common case of float arguments).
1 parent 01fb7bb commit 651df81

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,8 @@ def _get_papertype(w, h):
8888
return 'a0'
8989

9090

91-
def _num_to_str(val):
92-
if isinstance(val, str):
93-
return val
94-
95-
ival = int(val)
96-
if val == ival:
97-
return str(ival)
98-
99-
s = "%1.3f" % val
100-
s = s.rstrip("0")
101-
s = s.rstrip(".")
102-
return s
103-
104-
10591
def _nums_to_str(*args):
106-
return ' '.join(map(_num_to_str, args))
92+
return " ".join(f"{arg:1.3f}".rstrip("0").rstrip(".") for arg in args)
10793

10894

10995
def quote_ps_string(s):

0 commit comments

Comments
 (0)