No @Gerard, YOU weren't missing anything: since posting, have upgraded
PyCharm to 2022.3.2 and the complaints about 'Method 5' have
disappeared. Evidently a PyCharm issue!
Which alters the top-line question to: is numbers.Number the preferred
type-hint when multiple numeric types are to be accepted?
PS no Decimal(s) nor Fraction(s) in my situation, but may be worth
adding to a wider discussion...
On 06/02/2023 04.03, Weatherby,Gerard wrote:
> dn,
>
> I’m missing something here. Method 5 seems to work fine in PyCharm. I’m
> interpreting your statement as:
>
> from fractions import Fraction
> from numbers import Number
>
>
> def double(value: Number):
> if isinstance(value, Number):
> /# noinspection PyTypeChecker
> /return 2 * value
> raise ValueError(f"{value}of {type(value)}is not a Number")
>
>
> print(double(7))
> print(double(7.2))
> print(double(complex(3.2, 4.5)))
> print(double(Fraction(7, 8)))
> /# print(double("7")) PyCharm properly complains/
>
> *From: *Python-list <python-list-bounces+gweatherby=
uchc...@python.org>
> *Date: *Saturday, February 4, 2023 at 9:32 PM
> *To: *'Python' <
pytho...@python.org>
> *Subject: *Typing Number, PyCharm
--
Regards,
=dn