Skip to content

Commit 0458585

Browse files
committed
Handle more Expr warnings.
1 parent f3fd627 commit 0458585

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

numpy/f2py/symbolic.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def _pairs_add(d, k, v):
9999
del d[k]
100100

101101

102+
class ExprWarning(warnings.UserWarning):
103+
pass
104+
105+
106+
def warn(message):
107+
warnings.warn(message, ExprWarning, stacklevel=2)
108+
109+
102110
class Expr:
103111
"""Represents a Fortran expression as a op-data pair.
104112
@@ -481,10 +489,7 @@ def __getitem__(self, index):
481489
if not isinstance(index, tuple):
482490
index = index,
483491
if len(index) > 1:
484-
warnings.warn(
485-
f'C-index should be a single expression but got `{index}`',
486-
category=warnings.SyntaxWarning,
487-
stacklevel=1)
492+
warn(f'C-index should be a single expression but got `{index}`')
488493
return Expr(Op.INDEXING, (self,) + index)
489494

490495
def substitute(self, symbols_map):
@@ -520,8 +525,8 @@ def substitute(self, symbols_map):
520525
else:
521526
r += term.substitute(symbols_map) * coeff
522527
if r is None:
523-
warnings.warn('substitute: empty TERMS expression interpreted'
524-
' as int-literal 0')
528+
warn('substitute: empty TERMS expression interpreted as'
529+
' int-literal 0')
525530
return as_number(0)
526531
return r
527532
if self.op is Op.FACTORS:
@@ -532,9 +537,8 @@ def substitute(self, symbols_map):
532537
else:
533538
r *= base.substitute(symbols_map) ** exponent
534539
if r is None:
535-
warnings.warn(
536-
'substitute: empty FACTORS expression interpreted'
537-
' as int-literal 1')
540+
warn('substitute: empty FACTORS expression interpreted'
541+
' as int-literal 1')
538542
return as_number(1)
539543
return r
540544
if self.op is Op.APPLY:
@@ -1256,5 +1260,5 @@ def _fromstring_worker(s, dummy=None):
12561260
# f2py special dummy name
12571261
return as_symbol(r)
12581262

1259-
warnings.warn(f'fromstring: treating {r!r} as symbol')
1263+
warn(f'fromstring: treating {r!r} as symbol')
12601264
return as_symbol(r)

0 commit comments

Comments
 (0)