diff options
author | Nomura <nomura.rh@gmail.com> | 2023-09-07 20:26:20 +0200 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-09-09 19:03:22 -0400 |
commit | 5f46ea116c6f80edd3633c03aacd7427ef3d0cec (patch) | |
tree | 8a962727656fe58689e38b07296199bbd77d9b0a /mesonbuild | |
parent | b51bce070eead2b65e56f087acf23829a6304ae2 (diff) | |
download | meson-5f46ea116c6f80edd3633c03aacd7427ef3d0cec.zip meson-5f46ea116c6f80edd3633c03aacd7427ef3d0cec.tar.gz meson-5f46ea116c6f80edd3633c03aacd7427ef3d0cec.tar.bz2 |
Add support for padding zeroes in int.to_string() method
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/interpreter/primitives/integer.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/mesonbuild/interpreter/primitives/integer.py b/mesonbuild/interpreter/primitives/integer.py index b7f3532..50def2c 100644 --- a/mesonbuild/interpreter/primitives/integer.py +++ b/mesonbuild/interpreter/primitives/integer.py @@ -3,8 +3,8 @@ from __future__ import annotations from ...interpreterbase import ( - FeatureBroken, InvalidArguments, MesonOperator, ObjectHolder, - noKwargs, noPosargs, typed_operator, + FeatureBroken, InvalidArguments, MesonOperator, ObjectHolder, KwargInfo, + noKwargs, noPosargs, typed_operator, typed_kwargs ) import typing as T @@ -65,10 +65,13 @@ class IntegerHolder(ObjectHolder[int]): def is_odd_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool: return self.held_object % 2 != 0 - @noKwargs + @typed_kwargs( + 'to_string', + KwargInfo('fill', int, default=0, since='1.3.0') + ) @noPosargs - def to_string_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: - return str(self.held_object) + def to_string_method(self, args: T.List[TYPE_var], kwargs: T.Dict[str, T.Any]) -> str: + return str(self.held_object).zfill(kwargs['fill']) @typed_operator(MesonOperator.DIV, int) def op_div(self, other: int) -> int: |