Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The absence of labels [in ECL] is probably a good thing. -- T. Cheatham


devel / comp.lang.python / Re: mypy question

SubjectAuthor
o Re: mypy questionThomas Passin

1
Re: mypy question

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: mypy question
Date: Sat, 30 Dec 2023 09:14:05 -0500
Lines: 42
Message-ID: <mailman.90.1703945649.2892.python-list@python.org>
References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
<1d9aa14c-fd26-4afd-b2fc-a9e516878491@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 2Iuv5tPySjhuxGK3rWYLbg6xpvmvJDz9n2xNq2RpLOeg==
Cancel-Lock: sha1:youTo4ZZnpKUn+6FbBX/DbRZd8Y= sha256:S8OpdJs7CPlBK89v77+q1uz+YT0kFAWCbCbyrBOk1RA=
Return-Path: <list1@tompassin.net>
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=tompassin.net header.i=@tompassin.net header.b=fWGG1ClJ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.023
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'def': 0.04; 'error:':
0.05; 'karsten': 0.09; 'types.': 0.09; 'import': 0.15; 'syntax':
0.15; '3.10': 0.16; 'aside': 0.16; 'construct.': 0.16; 'dict':
0.16; 'grasp': 0.16; 'hilbert': 0.16; 'intent': 0.16;
'received:10.0.0': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'typing': 0.16; 'want,': 0.16;
'wrote:': 0.16; 'problem': 0.16; 'python': 0.16;
'subject:question': 0.17; 'instead': 0.17; 'to:addr:python-list':
0.20; 'seems': 0.26; 'error': 0.29; 'header:User-Agent:1': 0.30;
'am,': 0.31; 'program': 0.31; 'python-list': 0.32;
'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'regard': 0.32; 'but':
0.32; "i'm": 0.33; 'requires': 0.34; 'header:In-Reply-To:1': 0.34;
'trying': 0.35; 'using': 0.37; 'list': 0.39; 'use': 0.39;
'should': 0.40; 'pass': 0.64; 'clear': 0.64; 'your': 0.64; 'skip:t
20': 0.66; 'skip:t 30': 0.67; 'header:Received:6': 0.67;
'received:64': 0.67; 'that,': 0.67; 'exactly': 0.68; 'sequence':
0.69; '(you': 0.76; 'queries': 0.81; '10:02': 0.84; 'accurate.':
0.84; 'list]': 0.84; 'tiny': 0.84; 'union,': 0.84; 'variation':
0.91; 'skip:q 20': 0.95
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1703945646; a=rsa-sha256;
cv=none;
b=c99rMCz1THjGDFTrUbrT+b7/DGb0zOYUo97q0W3YbneE4phZBUV1E/vfK9Od+EhyOXI4b9
ySGleCtB0r9EjNc8D4xNjJZ14hwS+DH3tFM55WGRlrvSRTrYnpBe+FuYrmE3s/O6yuQXbb
A7xSSiL5gzb+mJKqQtJrTghlut61aUF3p1YAOP3kqcjSG7Gk2qxoH1qeNoxBjYbIBxlJpX
3lLtXMScZEoQguSL71nsh10KTeyOyNgjrIx++MkiC487W+/cFfBgj4cGGnpMdoZWj1O3xj
uPeISl35bMDimhD0pN2RQWIk/Lvh6jNBlCROSMG5FPKxPysRBkrLevXGPsSL2A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1703945646;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=nPF8avcGw62UZdHkgnf+9wTBofg9/p/gyhLT93ROSYg=;
b=Yzbt5S5vtoUA3bo6LwMh/ACIhhfKIhLVfNYjpkI71/TcX4sEXavN2gQ5EBFpbyhth/z9vG
uPF/jNBqBieZS0WnEGqA+Cq5Os9u6SnqxxmEcsxNy4Dv+zOMcPr7TGAwh/kgw9uLaz/IZW
HRt94+oK7BUaekEhF10Zf6gxRMmutfZSprklOV2+frcVi/w6OYI8Y7IA8C4djH0gMHxssJ
yNhralIGIg8eoKfmqKI24gBgUgOPogiWgZkm3+MenlaGgSFIm3LsuaZt4KUFy87Gzg3I0H
l8v/mVk4Z1YzZ6JkhJ1DhPMcZtxV2Qu2Lj+XL1C+lG8M2kZBPrXuR0xRopbedg==
ARC-Authentication-Results: i=1; rspamd-659dcc87c8-hshrf;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Oafish-Whispering: 525cff7c43707a20_1703945646309_1413620064
X-MC-Loop-Signature: 1703945646309:1113101823
X-MC-Ingress-Time: 1703945646309
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1703945645;
bh=nPF8avcGw62UZdHkgnf+9wTBofg9/p/gyhLT93ROSYg=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=fWGG1ClJMhkZFDVzGjVjbvS7q+WCpVWXVEeuvY8pIv8aZhGvI4oj88oDn6499IifG
Xjsi8GnvoewikjgtKy66u6MR0hjIou3G0i6e+quv67CvVfH9KgSnFmaEJ/dY3bGXoT
WA1ESbVHeeBZ3WsGcovz+9o7smGtgE88ec6escz4iy2zOtFDERGl0OPmp/f1OFd4Je
9TUcIN1eXCzIB/j7FJbFL1kwXdc18xJ1ftdYs0swPAvxCt8mtluYwi2XgV2KNoAeFL
XKamvCBa3AKadYTsqK+i5CwJLxIsd3FZ4m7mAzq3UOsRoxKkr7dWfqaV0c3PcMkfGW
Zn+t3R3DU1jjw==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
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: <1d9aa14c-fd26-4afd-b2fc-a9e516878491@tompassin.net>
X-Mailman-Original-References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
 by: Thomas Passin - Sat, 30 Dec 2023 14:14 UTC

On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote:
> I agree that mypy's grasp of my intent from
>
> queries:list[dict[str, str | list | dict[str, Any]]]=None,
>
> into
>
> "List[Dict[str, Union[str, List[Any], Dict[str, Any]]]]"
>
> seems accurate. I just don't understand why list[dict[str,
> str]] should not pass that construct.

I made a tiny test program with your type signature, and got this error
message from mypy:

c:\temp\python\typing_test.py:3: error: X | Y syntax for unions requires
Python 3.10 [syntax]

Aside from that, this variation causes no mypy error (you must use
Sequence instead of List), and is also more clear about what you are
trying to get:

from typing import Union, Sequence, Dict

DictType1 = Dict[str, str]
DictType2 = Dict[str, Sequence]
DictType3 = Dict[str, Dict]
QueryType = Sequence[Union[DictType1, DictType2, DictType3]]

def test_typing(queries:QueryType=None):
print(type(queries))

d1 = {'k1': 'v1', 'k2': 'v2'}
queries = [d1,]
test_typing(queries)

I'm not sure if this captures exactly what you want, but it avoids the
problem where mypy does not regard str and Union[str, list] as
equivalent types. I tested this using Python 3.12.


devel / comp.lang.python / Re: mypy question

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor