Skip to content

Commit 67b5a9d

Browse files
committed
Address DeprecationWarning-s for pyparsing functions
- 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"
1 parent b5c32f7 commit 67b5a9d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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)