Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

They are relatively good but absolutely terrible. -- Alan Kay, commenting on Apollos


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

SubjectAuthor
o Re: mypy questionAntoon Pardon

1
Re: mypy question

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

  copy mid

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

  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: antoon.p...@vub.be (Antoon Pardon)
Newsgroups: comp.lang.python
Subject: Re: mypy question
Date: Fri, 12 Jan 2024 14:23:43 +0100
Lines: 67
Message-ID: <mailman.17.1705065827.15798.python-list@python.org>
References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
<ad016be2-6d57-46d9-943e-1cb398b54e7f@vub.be>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de LCACdBB1Zdc9hsuXjB3emg/kLQGsys0KhJBSkLeZqwtg==
Cancel-Lock: sha1:TCKRjRG3sOQIg/pTKVvF7algmDc= sha256:3oxaKl5RxWSSMZ5fbCtmW+aCq2QtYXBn+jXKi6mCyo4=
Return-Path: <Antoon.Pardon@vub.be>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=vub.be header.i=@vub.be header.b=zfg/LBLU; dkim-adsp=pass;
dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; 'error:': 0.05; 'indicate': 0.05; '2023': 0.07; 'matches':
0.07; 'karsten': 0.09; 'much,': 0.09; 'schrieb': 0.09;
"shouldn't": 0.09; 'something,': 0.09; 'thinks': 0.09; 'types.':
0.09; '-&gt;': 0.16; '16:02': 0.16; 'antoon': 0.16; 'construct.':
0.16; 'dict': 0.16; 'dicts': 0.16; 'following.': 0.16;
'from:addr:antoon.pardon': 0.16; 'from:addr:vub.be': 0.16;
'from:name:antoon pardon': 0.16; 'grasp': 0.16; 'hilbert': 0.16;
'hint': 0.16; 'incompatible': 0.16; 'intent': 0.16; 'mats': 0.16;
'message-id:@vub.be': 0.16; 'pardon.': 0.16; 'schreef': 0.16;
'strings,': 0.16; 'wichmann': 0.16; 'subject:question': 0.17;
'values': 0.17; 'to:addr:python-list': 0.20; 'fri,': 0.22; "i'd":
0.24; 'anything': 0.25; 'seems': 0.26; '>>>': 0.28; 'header:User-
Agent:1': 0.30; 'dec': 0.31; 'wondering': 0.31; 'guess': 0.32;
'but': 0.32; 'particular': 0.33; 'header:In-Reply-To:1': 0.34;
'those': 0.36; 'missing': 0.37; "it's": 0.37; 'means': 0.38;
'two': 0.39; 'otherwise': 0.39; 'list': 0.39; 'both': 0.40;
'something': 0.40; 'should': 0.40; 'sorry': 0.60; 'above': 0.62;
'pass': 0.64; 'key': 0.64; 'skip:r 20': 0.64; 'your': 0.64;
'skip:t 30': 0.67; 'late': 0.73; 'signature': 0.76; 'moment':
0.81; 'queries': 0.81; 'accurate.': 0.84; 'indicates': 0.84;
'received:eurprd01.prod.exchangelabs.com': 0.84; 'recreation':
0.84; 'skip:q 20': 0.95
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=aS+J4g+2RufTXu9oUMIjoo7Tbf56cKmX/gcAy1vtK7n4JtCDeGyh5DgYXzJ2Bnl2QH1HHkncdpsG5JhzCq8/Sm1rgrN0YRrE+pOMSuxsKCaCfA7FqYmq5wCbB696GVqMpLgXlP6iZazsuwR1oEFL7KDa4o2pn7081GTHhFdZdCSZYsydvFGIzcUT+yKPpq3egTfYdS4RYOPVkT+N7RNs+ASbTIQP95ZqJCwy68pf7PluZDxq1nZk3gt5n+vY5Z1aeXFHdQsUUi9CSYBTswdJs4FG9SVGx8xfN04NIvG8KsK7OLbpcxHK+vhqpnRy91xE1WZKkOCc80447yuXK6IedA==
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=MwTbNfJRzu8XtsLmv9jnUzTyY5D6QfwGFpkOJ4gR1Lk=;
b=YPOqeIyTRLk/wdIEDy6wapJngMgFDbUeWp01Sxi1d8+S6tSC/EtC9JUjcjIRXQoX9r2nNQQ9Zzz3vZ7jEsOwflHGK5wUfE4HZAzy/cZ9lBQOQHkWAlR+4R2/oZqO+/hbq43NB0l9AB0aTOQqYHH+rEj4X3uBunDJtWVcXqfAThgmDdL00fqI9qH346pQmxy4wok8Rn8eNQ90mDREdpojI/rU9sBV3Q2mO9rWG774TpEVaXiNHbl7ZDq2YCR8h3eMWP/c4QXYnBsUtWGS4JNgJLZJdIe0EW+Ro4+eMfqc6GgGAxEXJBIY4FyXif7OuAArn1hiD+F0KwjElcYk+UT1WA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=vub.be; dmarc=pass action=none header.from=vub.be; dkim=pass
header.d=vub.be; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vub.be; s=selector1;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=MwTbNfJRzu8XtsLmv9jnUzTyY5D6QfwGFpkOJ4gR1Lk=;
b=zfg/LBLUHnELYYWAXt133u7Pr/1fBPfS0qdDVMO5dmLi1R9xGbj/hbaPDvTk2S71M5yQd0kh5JlNXqbaNynqgRHsX9b8TYg2gFsS8TGn0wVmL18ecQgpRqnpYHt+xmfWYbs5esvrPq7enfz/dMolLFVFHJ3EshmrknOlQ9xdyJw=
Authentication-Results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=vub.be;
User-Agent: Mozilla Thunderbird
Content-Language: nl-BE
In-Reply-To: <ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
X-ClientProxiedBy: AM0PR10CA0023.EURPRD10.PROD.OUTLOOK.COM
(2603:10a6:208:17c::33) To PR3PR01MB7986.eurprd01.prod.exchangelabs.com
(2603:10a6:102:171::5)
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PR3PR01MB7986:EE_|AS8PR01MB7462:EE_
X-MS-Office365-Filtering-Correlation-Id: f7ec402b-ddd3-4838-a773-08dc1371b34e
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: GND/CPWNmbIwnBr8tfclrctdrpZ7fyaOlE+yO0HYNmt2tIEYVAbSmohplhpFwQUrvCzWWO9RBnwgFlUL1jM/OhEU5GHTMY/pnEyiRQZwNfVbnNi9P1NgSD/4E+5K9NqBpbevB29J4M9MSZJVG181vjMBLjgcLF3MRZ5IibT5XeR2MZaA0NnFEVkUg6rsxvPnZTIaGUvkpws/9mTNlmcJzSz4djQDm2Fcz+aCFSbd+r+0HmROtpL6GBe5/3hptyA6hsNxnnIBakurChYYG0hPHtJTz99nwIo4wYtqjODnLnX5xNdJDe+w0t6WaIzrUX6pfzeTv5DhdxdbKi2bxs9Giz7B36SHOo47VohXsfPN7Ygqr7setWdCbgR6F0ZYf3cmKvVNelYXKeqslnnMTfxzt2Ayu+F8aBcmS+0SC4UtUXpWL9fiVU5HpCqo/SAL0EPiinE7NUqr2+Lld7vB4kxPrS4MErp/COp5Z2PGf3pDvD1NYkOQn8+zhVDHjW8n/LDnlSHM42bKkrjm1uf7fYlWAqPE56NRdHBhMfi0PSDZkH9y0zTjAquh0yXX/8iJLfdx041UjWh4f8VJb8V89jaDsIDDWk/yvor0mVBYAnaNNXLtWKP6IFi5WOvmAGs/km2m
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:PR3PR01MB7986.eurprd01.prod.exchangelabs.com; PTR:;
CAT:NONE;
SFS:(13230031)(39860400002)(366004)(346002)(376002)(396003)(136003)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(5660300002)(2906002)(44832011)(6486002)(86362001)(38100700002)(31696002)(478600001)(6506007)(33964004)(36756003)(2616005)(6512007)(3480700007)(41300700001)(786003)(316002)(8936002)(8676002)(66476007)(66556008)(7116003)(66946007)(6916009)(31686004)(43740500002);
DIR:OUT; SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: 68eUMiE0I6vK7uFkZmflggCQLDJ8v7oJGl3rAKxYW9Zs5
NbugVmDyzH/eIoEmYzBd4VG/db6N9Gipv5FUxfUjJ6VAb
VnQDpDz4cGMgfDAoPJB4MS3ktgcSxcjBo2m6BO0O/J1Fw
Tgh3PL6fFdkoA0oT7hs87XiYZsAZ4lAwUcu7kmYWihlkp
EI9Ahj7s/f1xbUOmf5BGq7cCLLtdvbxNh0NEv9D8R47B2
TprVobWx5JuZ7wgsZmYIaoEv/J7c9N9wb254TYfH7dtdE
ScBr41ZG1MQmli6FZocUItZw0G1eK4K9NgJep+RFgY19x
nCKxzoxPVVRB0AG/EqH4d4zihs/oa+PQKU7HX3JqC+raW
UB9fbFBzwiGHYxzt3LsOC48Sto3r8w/SXzqx61Ci64vJ+
1kXxXHv9HJrcuozSSpWoKL/G6h3tmsKlEGBOU/xehSSZ6
AwS9oHKOg29w140HN4C7738gA5MgTk27uxc5T2ERqm/xZ
HnEf1hAAkc0ndBpWvTk4s3h9eO3rKnKk6xbZ6V+1wx97S
qqVzmhURsUm0Lj8faoeTSy2579ZLDyfqSUulBLqiGo7SX
xlk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WVynFLY6EV+deocW5Achn8
X-OriginatorOrg: vub.be
X-MS-Exchange-CrossTenant-Network-Message-Id: f7ec402b-ddd3-4838-a773-08dc1371b34e
X-MS-Exchange-CrossTenant-AuthSource: PR3PR01MB7986.eurprd01.prod.exchangelabs.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2024 13:23:44.1657 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 695b7ca8-2da8-4545-a2da-42d03784e585
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: 4WPYpGsGLOzZC1DnfC5C6d3Sudw+5YdTfzsfdgzyAM5MLsi2+5zkMUD6VXjeFunTBoVrTgn60zPMG5Ievy6YUg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR01MB7462
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: <ad016be2-6d57-46d9-943e-1cb398b54e7f@vub.be>
X-Mailman-Original-References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
 by: Antoon Pardon - Fri, 12 Jan 2024 13:23 UTC

Op 29/12/2023 om 16:02 schreef Karsten Hilbert via Python-list:

> Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list:
>
>>> I am not sure why mypy thinks this
>>>
>>> gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected
>>> "List[Dict[str, Union[str, List[Any], Dict[str, Any]]]]" [arg-type]
>>> rows, idx = run_rw_queries(link_obj = conn, queries = queries, return_data = True)
>>> ^~~~~~~
>>>
>>> should be flagged. The intent is for "queries" to be
>>>
>>> a list
>>> of dicts
>>> with keys of str
>>> and values of
>>> str OR
>>> list of anything OR
>>> dict with
>>> keys of str
>>> and values of anything
>>>
>>> I'd have thunk list[dict[str,str]] matches that ?
>> Dict[str, str] means the key type and value type should both be strings,
> Indeed, I know that much, list[dict[str, str]] is what is getting
> passed in in this particular invocation of run_rw_queries().
>
> For what it's worth here's the signature of that function:
>
> def run_rw_queries (
> link_obj:_TLnkObj=None,
> queries:list[dict[str, str | list | dict[str, Any]]]=None,
> end_tx:bool=False,
> return_data:bool=None,
> get_col_idx:bool=False,
> verbose:bool=False
> ) -> tuple[list[dbapi.extras.DictRow], dict[str, int] | None]:
>
> Given that I would have thought that passing in
> list[dict[str, str]] for "queries" ought to be type safe.
> Mypy indicates otherwise which I am not grokking as to why.
>
>> but in your
>> retelling above you indicate lots of possible value types... actually the mypy guess
>> seems to be a pretty good recreation of your psuedo-code description.
> 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.

Sorry for the late reaction and may be I am missing something, but I was wondering if
your type hint for queries shouldn't be the following.

queries:list[dict[str,str]|dict[str,list]|dict[str,dict[str, dict[str, Ant]]]

My impression at this moment is that you are write something like: dict[str, str | int] as
as shorthand for dict[str, str] | dict[str, int]. But those two are different types.

--
Antoon Pardon.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor