Skip to content

Commit 6acfa57

Browse files
Address DeprecationWarning-s for pyparsing functions (#83)
- replace `setParseAction` --> `set_parse_action` - replace `setResultsName` --> `set_results_name` - replace `parseString` --> `parse_string` Fixes pyparsing-related deprecation warnings that show for python -Wall -c "import tunits"
2 parents b5c32f7 + f9ff8bd commit 6acfa57

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

tunits/core/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class ValueArray(Generic[ValueType2], WithUnit):
337337
def __init__(self, data: Any, unit: Any = None) -> None: ...
338338
def allclose(self, other: ValueArray | Value, *args: Any, **kwargs: float) -> bool: ...
339339
def unique(self: ArrayType) -> ArrayType: ...
340-
def __array__(self, dtype: DTypeLike = None) -> NDArray[Any]: ...
340+
def __array__(self, dtype: DTypeLike | None = None) -> NDArray[Any]: ...
341341
def __array_wrap__(self, out_arr: NDArray[Any], context: Any = None) -> NDArray[Any]: ...
342342
def __copy__(self: ArrayType) -> ArrayType: ...
343343
def __deepcopy__(self: ArrayType) -> ArrayType: ...

tunits/core/cython/unit_database.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class UnitDatabase:
6262
"""
6363
if formula in self.known_units:
6464
return self.known_units[formula]
65-
parsed = unit_regex.parseString(formula)
65+
parsed = unit_regex.parse_string(formula)
6666
result = Value(parsed.factor or 1)
6767
for item in parsed.posexp:
6868
result *= self._parse_unit_item(item, +1, auto_create)

tunits/core/cython/unit_grammar.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ scalar_combine = Combine(
4141
+ Optional('.' + Optional(Word(nums)))
4242
+ Optional('e' + Word('+-' + nums, nums))
4343
)
44-
scalar = scalar_combine.setParseAction(lambda s, l, t: [float(t[0])])('factor')
44+
scalar = scalar_combine.set_parse_action(lambda s, l, t: [float(t[0])])('factor')
4545

46-
number = Word(nums).setParseAction(lambda s, l, t: [int(t[0])])
46+
number = Word(nums).set_parse_action(lambda s, l, t: [int(t[0])])
4747
name = Word(alphas, alphanums)
4848

4949
negatable = Optional(Literal('-'))('neg')
5050
exponent = _maybe_parens(negatable + _maybe_parens(number('num') + Optional('/' + number('denom'))))
5151

5252
single_unit = name('name') + Optional('^' + exponent)
53-
head = Group(single_unit).setResultsName('posexp', True)
54-
times_unit = Group('*' + single_unit).setResultsName('posexp', True)
55-
over_unit = Group('/' + single_unit).setResultsName('negexp', True)
53+
head = Group(single_unit).set_results_name('posexp', True)
54+
times_unit = Group('*' + single_unit).set_results_name('posexp', True)
55+
over_unit = Group('/' + single_unit).set_results_name('negexp', True)
5656

5757
unit_regex = (
5858
stringStart

0 commit comments

Comments
 (0)