Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Today is the first day of the rest of your lossage.


devel / comp.lang.python / Re: Typing Number, PyCharm

SubjectAuthor
o Re: Typing Number, PyCharmWeatherby,Gerard

1
Re: Typing Number, PyCharm

<mailman.1774.1675686497.20444.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=26007&group=comp.lang.python#26007

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: gweatherby@uchc.edu (Weatherby,Gerard)
Newsgroups: comp.lang.python
Subject: Re: Typing Number, PyCharm
Date: Mon, 6 Feb 2023 12:11:31 +0000
Lines: 185
Message-ID: <mailman.1774.1675686497.20444.python-list@python.org>
References: <e818abc9-a531-67e1-1aca-d6770bca2c03@DancesWithMice.info>
<SJ0PR14MB5864560E58F201EB62B0F200B9D59@SJ0PR14MB5864.namprd14.prod.outlook.com>
<a7d6d84b-066e-e556-9d3b-939514df2b62@DancesWithMice.info>
<SJ0PR14MB586413905CB4C5AD76B4362FB9DA9@SJ0PR14MB5864.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de VapNniHZ+c0moP7zpH2OXAGBa+LBj3xol3otQTQUiiPA==
Return-Path: <prvs=0401e149d5=gweatherby@uchc.edu>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=uchc.edu header.i=@uchc.edu header.b=PByybXzA;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; 'pycharm': 0.04; 'parameter': 0.05; '2023': 0.07;
'pycharm.': 0.07; 'string': 0.07; 'wanting': 0.07; '=dn': 0.09;
'consistency': 0.09; 'fails': 0.09; 'int': 0.09; 'numeric': 0.09;
'received:namprd14.prod.outlook.com': 0.09; 'situation,': 0.09;
'snippets': 0.09; 'types.': 0.09; 'url-ip:151.101.0.223/32': 0.09;
'url-ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32':
0.09; 'url-ip:151.101.64.223/32': 0.09; '&gt;': 0.14; 'import':
0.15; 'url:mailman': 0.15; 'memory': 0.15; "'python'": 0.16;
'***': 0.16; 'alias': 0.16; 'aliases': 0.16; 'anticipation': 0.16;
'api.': 0.16; 'construct.': 0.16; 'decimal': 0.16; 'expected.':
0.16; 'float,': 0.16; 'hand,': 0.16; 'happen.': 0.16; 'idea!':
0.16; 'instead?': 0.16; 'integer,': 0.16; 'issue!': 0.16;
'subject:PyCharm': 0.16; 'typing': 0.16; 'unlikely': 0.16;
'url:peps': 0.16; 'url:urldefense': 0.16; 'url:v3': 0.16; 'well-
known': 0.16; 'wider': 0.16; 'yet?': 0.16; 'wrote:': 0.16; 'uses':
0.19; 'to:addr:python-list': 0.20; 'code': 0.23; 'url:listinfo':
0.25; 'seems': 0.26; 'attack': 0.26; 'object': 0.26; 'opening':
0.26; 'received:edu': 0.26; 'email addr:python.org&gt;': 0.28;
'raise': 0.31; 'think': 0.32; 'question': 0.32; 'checks': 0.32;
'objects': 0.32; 'python-list': 0.32; 'but': 0.32; 'header:In-
Reply-To:1': 0.34; 'complex': 0.35; 'fine': 0.35;
'header:Received:8': 0.36; 'possibly': 0.36; 'missing': 0.37;
'received:filterd': 0.37; 'received:pps.filterd': 0.37; "skip:'
10": 0.37; 'using': 0.37; 'url-ip:13.107/16': 0.38; 'way': 0.38;
'could': 0.38; 'two': 0.39; 'added': 0.39; 'adding': 0.39;
'this,': 0.39; 'date:': 0.39; 'list': 0.39; 'use': 0.39;
'methods': 0.39; 'still': 0.40; 'appears': 0.40; 'something':
0.40; 'try': 0.40; 'should': 0.40; 'charset:windows-1252': 0.60;
'provide': 0.60; 'email.': 0.61; 'method': 0.61; 'here.': 0.61;
'from:': 0.62; 'to:': 0.62; 'url-ip:151.101.0/24': 0.62; 'url-
ip:151.101.128/24': 0.62; 'url-ip:151.101.192/24': 0.62; 'url-
ip:151.101.64/24': 0.62; 'number,': 0.64; 'others,': 0.64; 're:':
0.64; 'your': 0.64; 'numbers': 0.67; 'types': 0.67; 'url-
ip:104.18/16': 0.67; 'know.': 0.68; 'url-ip:52.6/16': 0.69;
'within': 0.69; 'url-ip:lookup error': 0.70; 'older': 0.70;
'skip:f 30': 0.71; 'accepting': 0.75; 'features': 0.75;
'clicking': 0.76;
'received:nam10-bn7-obe.outbound.protection.outlook.com': 0.76;
'discovered': 0.80; 'links.': 0.81; 'attention:': 0.84; 'email
name:&lt;python-list': 0.84; 'fraction': 0.84; 'highlights': 0.84;
'interpreting': 0.84; 'i\x92m': 0.84; 'skip:& 50': 0.84;
'subject:Number': 0.84; 'three,': 0.84; 'type,': 0.84; 'type.':
0.84; 'union,': 0.84; 'upgraded': 0.84; 'return,': 0.91; 'union':
0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.edu;
h=from : to : subject :
date : message-id : references : in-reply-to : content-type :
mime-version; s=UCHC03162020;
bh=biWYowJII64RCNRVurs2TA6o5mVARXX3iNzgehBMPYc=;
b=PByybXzAiyZVLVSx1pSKOK7dq+5AkRjwNyGwpdC8XlzYRMT+19iyKWqY8H4u9naIIol+
xJIh/vV17lEIVHXtfV1k1nPILXSReS1leh7qnQ5TMHWOLtYAJrhgIextsHZ8nIeET/HK
JxdJvvcdD2ovvN4qHrMtjM7cIq/S7NEa4SG3VnM3tycfHv8Ike6VgnWp/30gx64bM6EG
EqtfUnRQTuBSFx5G9lBHuqmUXNXuagLZKnD3IPF0+AcRKBdEL8yir9SAEX6GgDN/ylYQ
0sFZ6QaWMCF8mGcGk6ZyXtbAW0oMq+51NPDV0JMsAFMTXqPbSJPvkogCkVc0hkJ7Ivmx VA==
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=SEQOEURQ5eRh+wmqP3aVHowcrThpG0zKAPRPUG8rE19qc+jUxKBcHi8jeY1hNu9hQXIjSqGF2fKPKuv6tvrAvEKTY7NEw2UuHnY1Swu65Zxd6e2vcaPW0wF2u5IeVHXIF/LlHvOnC6cftpFriQhfzTJfc4z3sfoenibnj1PwfhrS0JPHnyIH6x8I15repu9l/eJTjYOV4JIAvmpngNpLShERQn0yIl1amLFzjPlgpqt0rfxhms1Nz8H3DEM5N2oKjt6+p9afBskxPyESEYUniNvstvWoH6uznEobxcb9eYnrazATmpmFazXv7HnQyBWw8+RBTdpmiAQ8NhEXfuEhzQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=biWYowJII64RCNRVurs2TA6o5mVARXX3iNzgehBMPYc=;
b=Mur3IJ3St2BKZkaihy3CnNCyg784enp32k4Wwt3GpclKZobG1egCThI8pF8tqo39Wl7/83zMEFjsAFB2KdadolY1aEK+hhcWZ1qWA/1Rb5KEmRL+r/M7CDrl9dxOQLXs+nF/o5uxxzSRxGUr+azR5Hc8iMchIl/msWbcH6oKAcQp7Wz+4ZglM5C1mMW5+3SDomGCFV3fB+YBnl8OV4p75upCYQa5vvZAjh8beu2WehkpQGwiNZSxT1PPDZL+LRrJly3xECYEiVrh9yuXXms2Te7gGQc9YuqFO1Jqwoj1h5ij9emVcFxaheMKUi6WGeyI7VTFRR54clM5j+LuWnh+nA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=uchc.edu; dmarc=pass action=none header.from=uchc.edu;
dkim=pass header.d=uchc.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uchc.onmicrosoft.com;
s=selector2-uchc-onmicrosoft-com;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=biWYowJII64RCNRVurs2TA6o5mVARXX3iNzgehBMPYc=;
b=YcwMXpj9/KSutio0hew+6/irgYUitXvOn7cvpkWE5g0s3sIEELW+5t+GjjYT1xbt4XVLs81C9IJgYNQ8Rwg/lohzFiiEWGfRHcn+huH7YJJtwyhuqdgQqDfZYnqdDDGPQrlTezCKwhzIpny2qVknECRyfRemQD2/riWi3oMaWn8=
Thread-Topic: Typing Number, PyCharm
Thread-Index: AQHZOQoR+M6Iqjy7uUyVgElTAJgtCK7Ac59IgABRX4CAAQT5Eg==
In-Reply-To: <a7d6d84b-066e-e556-9d3b-939514df2b62@DancesWithMice.info>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: SJ0PR14MB5864:EE_|DS0PR14MB7133:EE_
x-ms-office365-filtering-correlation-id: d6cc7128-3416-4f33-5158-08db083b48ae
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: r3TukY/PDHKowBtO3tIKZP83+90tJ74M+HUkBlbIbC4DUNDgX/bdgGp14BzdMoFK3krqgHBKwn7Oyufv3X3WQjK6ZwVpLksA2KNzl41BSf5apXL8S8uMOIODR2KIJtR89E+OAjhwKxhjukdYrmLwgTjOGvjtQslqRQSlHzZHNB5ErmFwLWDkEVTNpimgTZ9koLNxKeeEt5ucHMQY8ytMqmOdiUl8JOuJ6wYaJtJKM+DUVhlfWRPJd4pJRTd88AHG94fjcUKGFdALCUYob3wZ/Wv8Qpop70Q4HjOeMW+FmTw5SuWD7fwEc7Iu74ojSrZU26P53xUhKeIhvAqftat+me2HNugFmNzxb2naO4v3cePV4FOVUZD1y6E0AYhX4rz9aPJp1pOEa4/cwJytWd3okUsshITf+OVuOuDw/FDY7swejjTabr6pkerEUWH7oBTk549779EjGtBE8HzoofFyoHQCiDSuSzXNxBnhRUUC8ZE8cSOdgkKBKn5dK+WTfpT7Pg7Vz6EJpnmZnoqLNx9Y8cB+LbGu1oAeHzf2EN10xW/iTuvU5qHG9s7glpuu9rca5LuC+hp9ex3BfFPDOB22NXVAl2EhRGNADrDIZlWD98nbpZCS+ww+JQQ7tlj3X3koGyskL/01ZO3vcL8ku6NotWtFc50Gy9QmPhOzNbXzT1Fmeud0PXd7aF7L23ZVive+LGrZIxBK5vRtHhfUXJOtO+fEGrAaWkeFv6d4yLppoZA=
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:SJ0PR14MB5864.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230025)(6029001)(4636009)(366004)(376002)(396003)(346002)(39850400004)(136003)(451199018)(52536014)(8936002)(64756008)(2906002)(5660300002)(786003)(41320700001)(166002)(6506007)(966005)(38070700005)(53546011)(86362001)(7696005)(38100700002)(316002)(75432002)(122000001)(26005)(9686003)(71200400001)(33656002)(186003)(478600001)(55016003)(41300700001)(110136005)(66476007)(76116006)(66556008)(66446008)(83380400001)(8676002)(91956017)(66946007);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: HQMgpB49GuPnhjl2brZ7xu/9TaI+Q9y5L+2Ola9LB2n04Chkz98jatgF
gioEGHgCOBUsM0vUlT0IkpgszKLVReiVlEKaq8+XB46DixUckJ7BZ1VE
iTYk26tl+hUjLK+xMl1twO7FAHSit0qAeeb27anSTWxDa6njcA2v9bnw
l2MLHhNZDEKPWTKP0ZUDB6vXIf/2F8N0lYcxS4RtS0NxD3J2Hqkevkef
2xsG7sP5w6K7dC5FJOIZfc6PYCEHT1jn0NiNppeDJ8S7SNEf15gvwRSX
TFpAdKWC36Lqrw/SxM6ep3QN9wX1kpGWB56WMzoRCNgDK/b31TQvUCiB
dF8NKjaOZakhcaOg0PLyTQ3HjG8v6ANGtGnYhBcjFRh0xGhyNIIbKCA/
Z90v1CO/xAdOuXwqJ1nrrF7gpsB3YwnH5E/9GqvBGjFR7Xai6tN9jTBk
50i8Pt6wI9lhlWuCa87BMV0Uxt/DmfN25PhlkwFZ1WYynfuj4NF8RHsQ
FeYvm8vkVjbgLpCywCuA976NSf0kT5FKyWVV4S1FrXQKrDjbleeW4ApO
UcWCMNC1zAIesMZ2BudP5GDrFI+vYkKB/fOWZZPxDP6/mGtnypjvvR+J
NHSlbhYLxE6rrwCyi6OIB2AYha2f+arQCc9O0GHMuie4i2dNIOf3+ZzS
f40H9kGCzrwJymlkLLnr4OSqdifQKVITdj6/0DJklxynv8UksZeE05MF
CZP7DDARO0YeL0nAJCDgDA5yjS+w8uAEoNa+Qv/29DwlMmwz+aYtC0xh
pjA/JpeqwWz8t5B+dB6w/S5vqifKROJvHhl0JPlgqt6lE3m6raYHPvBE
aSVqtDELXUa7HMvIIBdug6w16QhB+P6xnB3pZu3M6k9wKLpMgz7HLkOu
LphxGNNRh2Ev2N7aY8jgJ4c38QTM40g9RXIhe7/E3+jFWYF8MK+GN8hm
SBoZCCM6Iv9d7AkyM1IyXNm6bCLTpgb5Sl74VfP02GpqM1T6wQikeS7j
BeEmnGfIAq90jel9xrfrotwlrqm+V9i5HQbANGFANdjRRbgF5En9RT5n
XAKblzcoZ01CwVz/qCvxEUnu+/U9aA4ZrvQbbWPgnOJJMDC+pW5F90jP
wMbqC2hgSAcstzrdKbX+/KPWQqaz2sK44PZVk0w1yix6/u3AL5klLk+M
HGQ6JBiGWe2GEZ1caZN2FI1THSOLpg1MKI8+A9LX6Ag6gYpwhZ+ijSHb
gll9dcA9C4OTKbpHtQfFt275d6K6j8WxFFHizIWz3C/OlYzs06hpnoT2
3y16tdjEjDVf9SzTQh3If7vaffxpJQ0a+3jn4/hsSBfVe/uc8zQ/ey9j
kbMELgX9bXRfQaGRf7zFtHDqarhdVoRLB5oxCdDnO5bVHUtNYPCJUymu
0egkgwHO9v4si1jPoOo81dqAloUWNY9ulsflXl8Wh/IUBWDtm6ev+aC4
xPfTzhcyAJRhmZ78YHRb0+wMvs9FvO4gcvhDzKfDF6eLkcZt+04PIc8n
6Bwc3kqssNxu56+fFEmGvnmYk+PYsgDrNmoYzNqvGGJhC7fsPaHQqFFt
ZtYRgeUQX7jUil5jj23VYKv8dNZWDcf0Lf8RNPQcfADb8qY+JjkEwg
==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: SJ0PR14MB5864.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: d6cc7128-3416-4f33-5158-08db083b48ae
X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2023 12:11:31.8064 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 5c82d83a-818a-4c16-b540-ded2344a7ad3
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: C4uVD+T95+tYckcDnCzCoEMnxwJgNZ+nqB9C5ADqe5cx1THFqbAhUkNp3Bwm2vHGxybXcBCIZLSg15NOker+Gg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR14MB7133
X-Proofpoint-ORIG-GUID: 5B3SdSxSjf0SNkjROJKRlx-UDS-TCvj-
X-Proofpoint-GUID: 5B3SdSxSjf0SNkjROJKRlx-UDS-TCvj-
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1
definitions=2023-02-06_06,2023-02-06_02,2022-06-22_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
priorityscore=1501
malwarescore=0 lowpriorityscore=0 suspectscore=0 phishscore=0
mlxlogscore=999 spamscore=0 impostorscore=0 mlxscore=0 adultscore=0
bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1
engine=8.12.0-2212070000 definitions=main-2302060103
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <SJ0PR14MB586413905CB4C5AD76B4362FB9DA9@SJ0PR14MB5864.namprd14.prod.outlook.com>
X-Mailman-Original-References: <e818abc9-a531-67e1-1aca-d6770bca2c03@DancesWithMice.info>
<SJ0PR14MB5864560E58F201EB62B0F200B9D59@SJ0PR14MB5864.namprd14.prod.outlook.com>
<a7d6d84b-066e-e556-9d3b-939514df2b62@DancesWithMice.info>
 by: Weatherby,Gerard - Mon, 6 Feb 2023 12:11 UTC

“is numbers.Number the preferred type-hint when multiple numeric types are to be accepted?”

I don’t know.

On the one hand, it is a well-known type, so it should be recognizable to users of an API. On the other hand, Number is entirely abstract, so it doesn’t provide useful type checking for the implementation; I had to add # noinspection PyTypeChecker to 2 * value to keep PyCharm from complaining. Additionally, it does not include the Decimal type. Interestingly, It was added in 2007 in anticipation of “if and when overloading based on types is added to the language.” This now seems unlikely to happen. ( https://peps..python.org/pep-3141/#rationale )

On the other hand, a specific type alias is clearer to type checkers and possibly to the user of an API?

Experimenting, it appears isinstance checks of Type Aliases don’t work before 3.10, and its TypeAlias construct. That is:

Numeric = Union[int, float, complex, Fraction]

def double(value: Numeric):
if isinstance(value, Numeric):
return 2 * value
raise ValueError(f"{value} of {type(value)} is not Numeric")
Fails but

Numeric : TypeAlias = Union[int, float, complex, Fraction]

def double(value: Numeric):
if isinstance(value, Numeric):
return 2 * value
raise ValueError(f"{value} of {type(value)} is not Numeric")

works (>= 3.10)

From: dn <PythonList@DancesWithMice.info>
Date: Sunday, February 5, 2023 at 2:54 PM
To: Weatherby,Gerard <gweatherby@uchc.edu>, 'Python' <python-list@python.org>
Subject: Re: Typing Number, PyCharm
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

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.edu@python.org>
> on behalf of dn via Python-list <python-list@python.org>
> *Date: *Saturday, February 4, 2023 at 9:32 PM
> *To: *'Python' <python-list@python.org>
> *Subject: *Typing Number, PyCharm
>
> *** Attention: This is an external email. Use caution responding,
> opening attachments or clicking on links. ***
>
> Do we have a typing type-hint for numbers yet?
>
>
> Often wanting to combine int and float, discovered that an application
> was doing a walk-through with/for uses three numeric types. Was
> intrigued to note variance, in that the code-set features two different
> methods for typing, in this situation:
>
> def func( value ):
> ...using value...
>
> where value may be an integer, a floating-point value, or a
> complex-number (but not decimal-type).
> NB code snippets from memory (cf copy-paste)
>
>
> Method 1 (possibly older code):-
>
> from typing import Union
> ...
> def fun( value:Union[ int, float, complex ] ):
>
>
> Method 2:-
>
> def fun( value:int|float|complex ):
>
>
> Pondering this, realised could use an alias to de-clutter the
> function-definition/signature:
>
> Method 3:-
>
> number_type = int|float|complex
> ...
> def fun( value:number_type ):
>
>
> If it was important to have type consistency within the union, eg
> argument and return, could go for:
>
> Method 4:-
>
> from typing import TypeVar
> number_type = TypeVar( 'number_type', int, float, complex )
> ...
> def fun( value:number_type ):
>
>
> Then remembered the way we'd code an execution-time check for this using
> isinstance():
>
> Method 5:-
>
> from numbers import Number
> ...
> def fun( value:Number ):
>
>
> Each of these will execute correctly.
>
> All cause PyCharm to object if I try to call the fun(ction) with a
> string parameter - and execute an exception, as expected.
>
>
> Accepting all the others, am curious as to why PyCharm objects to Method
> 5 with "Expected type 'SupportsFloat | SupportsComplex | complex |
> SupportsIndex', got 'Number' instead? - yet still highlights the
> erroneous string parameter but none of the 'legal' data-types?
>
> As soon as a list (in this case types) reaches three, my aged-eyes start
> to think de-cluttering is a good idea!
>
> Do you know of another way to attack this/more properly?
>
> --
> Regards,
> =dn
> --
> https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gqIbcK1zaXmlo5y6741fRwcBUcDfxPNkiA4Jy_NHr9nEno2HaBGZYMuitXeivWrGwTJtds01pHdFfiY_Y5bnmsq_NQ$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gqIbcK1zaXmlo5y6741fRwcBUcDfxPNkiA4Jy_NHr9nEno2HaBGZYMuitXeivWrGwTJtds01pHdFfiY_Y5bnmsq_NQ$> <https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gqIbcK1zaXmlo5y6741fRwcBUcDfxPNkiA4Jy_NHr9nEno2HaBGZYMuitXeivWrGwTJtds01pHdFfiY_Y5bnmsq_NQ$>
>

--
Regards,
=dn


devel / comp.lang.python / Re: Typing Number, PyCharm

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor