Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

I bet the human brain is a kludge. -- Marvin Minsky


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

SubjectAuthor
o Re: mypy questionKarsten Hilbert

1
Re: mypy question

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

  copy mid

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

  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: Karsten.Hilbert@gmx.net (Karsten Hilbert)
Newsgroups: comp.lang.python
Subject: Re: mypy question
Date: Fri, 29 Dec 2023 21:33:36 +0100
Lines: 57
Sender: <karsten.hilbert@gmx.net>
Message-ID: <mailman.83.1703882019.2892.python-list@python.org>
References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
<9b180ed9-0393-4db4-a45c-391c115aaeef@wichmann.us>
<ZY8tIBxBBrYEoHQc@hermes.hilbert.loc>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de BcMbIMDz/pNc1ShvcQbDvgGSDoDjdrFAuaCL4FlR8mWQ==
Cancel-Lock: sha1:llzXC8ykHbFO0pIFz4s+kMc9Q3A= sha256:mtOGQap40c6NTnztFADyS58p6Lrl+cEUy4yE+WzbUOQ=
Return-Path: <karsten.hilbert@gmx.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=gmx.net header.i=karsten.hilbert@gmx.net
header.b=mRxoTgAM; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.030
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'def': 0.04; '2023': 0.07;
'received:212.227': 0.07; 'gpg': 0.09; 'karsten': 0.09; 'schrieb':
0.09; 'then.': 0.09; '1713': 0.16; 'mats': 0.16;
'received:212.227.15': 0.16; 'skip:> 10': 0.16; 'violation': 0.16;
'wichmann': 0.16; 'subject:question': 0.17; 'to:addr:python-list':
0.20; 'fri,': 0.22; 'function': 0.27; 'attempt': 0.31; 'dec':
0.31; 'think': 0.32; 'expand': 0.32; 'appreciated.': 0.34;
"didn't": 0.34; 'header:In-Reply-To:1': 0.34; 'trying': 0.35;
"it's": 0.37; 'otherwise': 0.39; 'list': 0.39; 'use': 0.39;
'something': 0.40; 'should': 0.40; 'sorry': 0.60; 'provide': 0.60;
'above': 0.62; 'to:': 0.62; 'received:212': 0.62; 'research':
0.64; 'skip:r 20': 0.64; 'skip:t 30': 0.67; 'ignore': 0.71;
'signature': 0.76; 'indicates': 0.84; 'mind,': 0.93; 'skip:q 20':
0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=s31663417; t=1703882017; x=1704486817; i=karsten.hilbert@gmx.net;
bh=/irVP7mplE4+qfwI6qGB5OypLQuiVYn2tdLE12qOwZ4=;
h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To;
b=mRxoTgAM9QIHeYG47mxScYuAlJ2kwph3SQSM05Tx3mUqzf0JpV9ZG8Cdq8mmNfXN
OhP1c8omGbZsU0nFIfTCnLtgd66w9NsBJqsCzAme1NjRDvsjwg9amze0lA+3S/AoU
iCKBkVW9ZIUAY9BHP/R89Vuk1l6prr8O9sZNRy8bOKEHQdDemQYI2IJbD+bPQw5T/
/8oJDRcaxAuTtiN0/rVSOQCkQo9JvJYodnazUS028J61UOO/+6FdrWN7Eq2hZaHfS
kSm6yt/A+u1tHyUIv7D3V7gGxT0vK67PJ4ldKM+uy6daf4+iYJg/XRMUv5aOsVo9H
vTSRChpQdvnleX+QBg==
X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a
Content-Disposition: inline
In-Reply-To: <9b180ed9-0393-4db4-a45c-391c115aaeef@wichmann.us>
Ma_X_il-Followup-to: d
Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net
Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net
X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net
X-Pri_X_ority: 2 (High)
X-Provags-ID: V03:K1:juhcSSFXoUiDTqOqzZp2scObecQ+cZLvkj2ONbrPCc1oycu9nvM
IE5nOlz8hg36/bR1ili3Izw84ywcOT20M71kCkhMY/YMGyd68dwJzh8aZSpQ64i/kIuib9M
n1paUw20Vw5Fzfu+R+cKnYP3G8sNmdAZ1ZQMSI0tp4H+Ol2Ngfh+jFfHY/l4oYGeWZipKz/
6Ea6LDtrBlPfGMs1mR3pw==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:Hp1Ny+HB1mI=;nzw1xguQwFqJwLQWBQ3T9is2IYC
WuY0MMK9GbLvX45GH3HZNJrizklH+PG4qRjvJN53A8Mn4hbZgIk3XLCuWWwtaVOI4Tu95bv8M
7VBWt/VJzgv4HcIERmF0cl77mB6/t8IkgBWf3LmqS6r4448Zv2GZ/s4HRhNE3OttDDLY2xPrX
9Zcv3qar1/P2doBE4D2M48wQAWoJhvNnUpXtEvPCggJrpbGVpCw4jHGPIQwZtXzZc3mu7Qy5g
CbMRKL2I/kjiTv+I8UabP+a+VK6R7+JrOnYm8QWS3cebSUCf3D4nmdL6opICS4Fsn8qQ9XzgA
ARi6UNOqUmMYo9nIimn75CMhk2f0GHYMYOqm2LdA5Ypvn/fswibWc4OBcdP76cE1WwcCVHmhM
eJciij/hHsd9+kFNuKg8sZ9fabvwD5PuUVDizeg/6tI+GePAzE7ysTpAvKPccQsIxzEYvm65y
5xrTi/CZPMEXcNrsm2FqBlSKN6KVS8tl0qUXyFuenqWFnq/fqbr56UQ6xnYNMsANqjDPL10k4
4U1dMJ0VWUDcRgoMn+PC+gljIQ7uMSRuwAumrpU9GknC+7X2w2mI4uJBb25utUuzIa9mQzGp7
ZgQo05UT/uJwjEsVB+egYJBAkopxV5dAYHDvPJzyE34JlUWI4dyQcHWPbu/TYEezsMzr3Xi6e
x1vqJHSz2ausbNBJ11aPxxnTg7uTTqo3IWNwYpVWe//gj0SOxGWGLXh/zlFYedsmVHKGGDc2k
4tcBBGBjX8HcRhD3YUCRmAaQ6ygMmE1WYQ05y8RLdaZ+H4FjbDalEGgnwRa1A07v8g7EGIvrV
6+rSBIpPIg3akCiGY+xFZpvkWk/p6gNipqID08yimGZ37nHAyRDbFo/hKENfGRG4TR7EyFY03
QmHKWItIc1VGFmthKBO39z9Eb9aRN7cYNm+RyNdIAKlbPzwqjELPm39Lya+MGQe9fJl5+LN8b
4fPKJg==
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: <ZY8tIBxBBrYEoHQc@hermes.hilbert.loc>
X-Mailman-Original-References: <ZY64YbzKqfGbZcpC@hermes.hilbert.loc>
<fd6bbad8-2736-4305-982d-eabbf212a920@wichmann.us>
<ZY7faSj-OA-lDqxC@hermes.hilbert.loc>
<9b180ed9-0393-4db4-a45c-391c115aaeef@wichmann.us>
 by: Karsten Hilbert - Fri, 29 Dec 2023 20:33 UTC

Am Fri, Dec 29, 2023 at 11:04:59AM -0700 schrieb Mats Wichmann via Python-list:

> >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.
>
> ah... didn't grok what you were asking, sorry - ignore my attempt then.

Never mind, the attempt to help is appreciated.

> So you are passing something that has been typed more
> narrowly than the function parameter.

That would then sort of skirt on violation of the Liskov
principle, of which I learned while trying to research this
mypy behaviour.

However, I would not think the above to be a narrowing-down
as it just *selects* one of the explicitely "legal" options.

list[dict[str, str | list | dict[str, Any]]]

should AFAICT expand to:

list[dict[str, dict[str, Any]]]

OR

list[dict[str, list]]

OR

list[dict[str, str]]

the last of which should provide coverage of

[{'some key': 'some value'}]

> Can you use a TypeGuard here?

Not from what I understand about them...

Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B


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

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor