Skip to content

Commit c360d67

Browse files
committed
fixed #984 pyparsing deprecations
1 parent 1486d90 commit c360d67

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

changes/984.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed Pyparsing deprecation warnings

src/sisl/unit/base.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ def _float(t):
388388
return f
389389

390390
# The unit extractor
391-
unit = pp.Word(pp.alphas).setParseAction(_value)
391+
unit = pp.Word(pp.alphas).set_parse_action(_value)
392392

393393
integer = pp.Word(pp.nums)
394-
plusorminus = pp.oneOf("+ -")
394+
plusorminus = pp.one_of("+ -")
395395
point = pp.Literal(".")
396396
e = pp.CaselessLiteral("E")
397397
sign_integer = pp.Combine(pp.Optional(plusorminus) + integer)
@@ -407,22 +407,22 @@ def _float(t):
407407
+ pp.Optional(exponent)
408408
),
409409
] # [0-9].[0-9][E+-[0-9]]
410-
).setParseAction(_float)
410+
).set_parse_action(_float)
411411

412412
# def _print_toks(name, op):
413-
# """ May be used in pow_op.setParseAction(_print_toks("pow", "^")) to debug """
413+
# """ May be used in pow_op.set_parse_action(_print_toks("pow", "^")) to debug """
414414
# def T(t):
415415
# print("{}: {}".format(name, t))
416416
# return op
417417
# return T
418418

419419
# def _fix_toks(op):
420-
# """ May be used in pow_op.setParseAction(_print_toks("pow", "^")) to debug """
420+
# """ May be used in pow_op.set_parse_action(_print_toks("pow", "^")) to debug """
421421
# def T(t):
422422
# return op
423423
# return T
424424

425-
pow_op = pp.oneOf("^ **").setParseAction(lambda t: "^")
425+
pow_op = pp.one_of("^ **").set_parse_action(lambda t: "^")
426426
mul_op = pp.Literal("*")
427427
div_op = pp.Literal("/")
428428
# Since any space in units are regarded as multiplication this will catch
@@ -478,7 +478,7 @@ def base_action(toks):
478478
return toks[0][0] * toks[0][1]
479479

480480
# We should parse numbers first
481-
parser = pp.infixNotation(
481+
parser = pp.infix_notation(
482482
number | unit,
483483
[
484484
(pow_op, 2, pp.opAssoc.RIGHT, pow_action),
@@ -501,8 +501,8 @@ def same_group(A, B):
501501

502502
def _convert(self, A, B):
503503
"""Internal routine used to convert unit `A` to unit `B`"""
504-
conv_A = self._p_left.parseString(A)[0]
505-
conv_B = self._p_right.parseString(B)[0]
504+
conv_A = self._p_left.parse_string(A)[0]
505+
conv_B = self._p_right.parse_string(B)[0]
506506
if not self.same_group(self._left, self._right):
507507
left = list(self._left)
508508
right = list(self._right)
@@ -549,7 +549,7 @@ def convert(self, *units) -> Union[float, Tuple[float]]:
549549

550550
elif len(units) == 1:
551551
# to default
552-
conv = self._p_left.parseString(units[0])[0]
552+
conv = self._p_left.parse_string(units[0])[0]
553553
self._left.clear()
554554
return conv
555555

0 commit comments

Comments
 (0)