Basically i got below warning in PyCharm in the statement math.isclose(a_val, b_val)
Expected type 'SupportsFloat', got 'Number' instead
Minimal, reproducible example as below.
from numbers import Number
import math
a_val = '123'
b_val = 123.4
if isinstance(a_val, Number) and isinstance(b_val, Number):
is_close = math.isclose(a_val, b_val, abs_tol=0.5)
In reality, a_val and b_val are sourced somewhere else which could return float, integer or string. If both a_val and b_val are numeric, I want to check if they are almost equal. Otherwise just ignore it if any of them is string.
Question - what is the best way of type checking before passing a_val and b_val to math.isclose() ? What change should be done to clear the PyCharm wanring?