Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

You will have a head crash on your private pack.


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

SubjectAuthor
* Re: mypy questionThomas Passin
`* Re: mypy questionGreg Ewing
 `- Re: mypy questionKarsten Hilbert

1
Re: mypy question

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!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 16:06:11 -0500
Lines: 46
Message-ID: <mailman.100.1703971521.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>
<04fd6edd-d6f3-43b6-9b5a-f279c34e1724@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 7gRTHRSg+qTMJ26B871r3wNNZi73DDKBSfuVjckAJNYw==
Cancel-Lock: sha1:XmhYs2qk/7uMpq5qzczbYrX+xO0= sha256:aadTw8pqZE6VLw5LlI67VH+T1x3jdcJxlAnj8sjtQr4=
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=xRa1owyU;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.024
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'def': 0.04; 'error:':
0.05; 'skip:\xc2 30': 0.07; 'suggestion': 0.07; 'karsten': 0.09;
'skip:\xc2 20': 0.09; 'import': 0.15; 'syntax': 0.15; '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; 'cannot': 0.25; '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; 'same': 0.34; 'requires': 0.34; 'header:In-
Reply-To:1': 0.34; 'trying': 0.35; 'meaning': 0.35; 'work,': 0.36;
'using': 0.37; 'list': 0.39; 'use': 0.39; 'should': 0.40; 'above':
0.62; 'pass': 0.64; 'clear': 0.64; 'your': 0.64; 'skip:t 20':
0.66; 'types': 0.67; 'skip:t 30': 0.67; 'header:Received:6': 0.67;
'received:64': 0.67; 'that,': 0.67; 'exactly': 0.68; 'sequence':
0.69; 'within': 0.69; '(you': 0.76; '8bit%:35': 0.81; 'queries':
0.81; '10:02': 0.84; 'accurate.': 0.84; 'list]': 0.84; 'tiny':
0.84; 'union,': 0.84; 'union': 0.91; 'variation': 0.91
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1703970373; a=rsa-sha256;
cv=none;
b=7Bwb3g8LRGOe2RGufzwZnDjHtJZaQv7rAVW2FbOnEzJvWR9vfOqZAh/zxowRhLKLwiOg52
/Gp2Mqg92Plg14P302eGtL6recBcvi78nsxDMn/3UV0HegTveSU0n5TodHgyn3uisdngwt
yRpbfFI5xG1/qLV8iHgStGdASnGN5PAIxHeuegqF+NFhN0hq2iKzeKiOcdi5thHbOCJwAX
RWWRK9BOUm1c8izHTgGpObwXWva+Vvq8LSwJ/eag0YrlTZtELkVwOFHpMkSQA1NCMlog5Q
zK/0EyXmLzgALwQDUVJf29l370ZxuYt/SH8RcRW3ELuP7GpBsBHs0UEnO7lsvQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1703970372;
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=hvrc6pN7cqdoY2godnb+2i5PvW3/A3O1a5zMYnjn0Kg=;
b=96MKjr4OrincUkEmJUHKK2kCVtUJDG+2zuPNt0Kfyu8/1scT0XmCcCL7KcuDGynFxir6Ph
mTc0GlSmmm1k4w/FaTFU2vs/FmcoQUIJRcE4j/vWl5H7cZLSsF1VkrouqFQ4q1E8M6+zIe
DpzC2jYODZJjLPKLt5td48NjC8MlVtsLmuKW3w12hmdWNT23jnpqkPG9sa+mzAAkGwX7dc
Z+CuBwqqDpkLexjD2ieG6+UuW8PcMa+BWziI8my5sJbsEdp9BWC7j0LffFy+JsyhyaM/lN
ZwLlhNftpC+frVHronP49jbmNgv2ah2hfv2oIQQGzDr0fsWVX3tEzJfnDrJlzg==
ARC-Authentication-Results: i=1; rspamd-659dcc87c8-vsb27;
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-Tart-Bored: 47c1a36d718aa22a_1703970373196_613977242
X-MC-Loop-Signature: 1703970373196:4270736960
X-MC-Ingress-Time: 1703970373196
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1703970372;
bh=hvrc6pN7cqdoY2godnb+2i5PvW3/A3O1a5zMYnjn0Kg=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=xRa1owyU7DHSE0N9ntanUaDJBZd312UQsM9c5lcztqzMJSSKJXS2GJ9j8hLCJVyoo
KpTU83/6mwXoCICfsk55wzsAEUOijt6XrLbSR5DN5ULGMkfeRnbEEFbA4Ob2HPxTG2
lDCuefaZN+74hPnjg21MJa+IkB/bdn1UkR6G+dW+pDTENWPYgS9uPI+0DpxJ25Kl4W
AhDIk8nSth1uyVpqisLob5onIV1XGaJBbZbG0sVTIcCtpWmMz95XEze3xQcGEQ3EPz
JzdMePUPN/Iim/XN5lyfdeg/wtToBTrZ5eC6WTgYuyquEQHACZ+M5p5seHzBTeBGKR
2W/KFFUHFmG6w==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <1d9aa14c-fd26-4afd-b2fc-a9e516878491@tompassin.net>
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: <04fd6edd-d6f3-43b6-9b5a-f279c34e1724@tompassin.net>
X-Mailman-Original-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>
 by: Thomas Passin - Sat, 30 Dec 2023 21:06 UTC

On 12/30/2023 9:14 AM, Thomas Passin via Python-list wrote:
> 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.

In doing more testing, I have learned that my suggestion above does
work, *except* that you cannot mix-and-match different DictTypex types
within the same Sequence - meaning within the same query argument. Any
of the Union types is OK but they all have to be the same in any instance.

Re: mypy question

<kvbqnmF3cpkU2@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: mypy question
Date: Sun, 31 Dec 2023 13:25:26 +1300
Lines: 10
Message-ID: <kvbqnmF3cpkU2@mid.individual.net>
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>
<04fd6edd-d6f3-43b6-9b5a-f279c34e1724@tompassin.net>
<mailman.100.1703971521.2892.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net MYKOKqX9KXnqa3PZciHTaA4DjZelmPs/hZ6dS8DikPEoiqfi7F
Cancel-Lock: sha1:5L3ai4Z7zoIn47en41PAn/ZsJng= sha256:KnaWOP0PuAm9WERsIzUmyitbUl3DwqU7VepChjHZY44=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.100.1703971521.2892.python-list@python.org>
 by: Greg Ewing - Sun, 31 Dec 2023 00:25 UTC

On 31/12/23 10:06 am, Thomas Passin wrote:
> my suggestion above does
> work, *except* that you cannot mix-and-match different DictTypex types

Have you tried declaring the argument as a Mapping instead of a dict?
Seeing as Thomas Passin's Sequence experiment worked, it seems like this
should work too.

--
Greg

Re: mypy question

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

  copy mid

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

  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: Sun, 31 Dec 2023 14:49:44 +0100
Lines: 7
Sender: <karsten.hilbert@gmx.net>
Message-ID: <mailman.103.1704030587.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>
<04fd6edd-d6f3-43b6-9b5a-f279c34e1724@tompassin.net>
<mailman.100.1703971521.2892.python-list@python.org>
<kvbqnmF3cpkU2@mid.individual.net>
<ZZFxeIieVPI9jNI2@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 1Hkzvc9giZvHNVCcASZG5ANQAxpTzzMRYQ6MTpAYD58g==
Cancel-Lock: sha1:drmu2KOh5qCFAY/Sdtbzi6BM5sc= sha256:Onz0KeHKYUm/Zu92dVEGbD2E07t8PoC7GZQ7c/sJ3jw=
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=GrveWMmI; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:212.227': 0.07;
'ended': 0.09; 'gpg': 0.09; 'karsten': 0.09; '"import': 0.16;
'1713': 0.16; 'dict': 0.16; 'received:212.227.15': 0.16;
'subject:question': 0.17; 'to:addr:python-list': 0.20; 'header:In-
Reply-To:1': 0.34; 'using': 0.37; 'thanks': 0.38; 'list': 0.39;
'received:212': 0.62; 'sequence': 0.69
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=s31663417; t=1704030585; x=1704635385; i=karsten.hilbert@gmx.net;
bh=KOxhNKe9gEQkSxKzLNoeGBPnCTfPS3IophT1CV2oDoM=;
h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To;
b=GrveWMmI5IRV478mXInHAfFI76MoTiH6WWlrDEzijurxAwpE54+ihKg4bRs9TRVW
urVOu6fuzxBHzcyZPw/FVBgJob6EbSVgv6aNk21Pnq87qy2xjilT3JkgJa4Y60gdB
26/SfIw5Nc9TTL7qWP5jB+mDos/cTV32NIyFQNxrtL7RzSWxzdTueZ3fQVYbaEH+z
eSvpxPCKhQUSWlab+I2ORrBuTaadu5vXW58d3bs1ftx9RPsmcRxI0QlPpMFTUdoW7
AQcC8hpQ1yJveWr2I68eiF7qDPVHawpNqq77MMIl2JFd9AFc+K8v3esqnJPchgi1Q
F36wCPgBmOv+Mlx/cQ==
X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a
Content-Disposition: inline
In-Reply-To: <kvbqnmF3cpkU2@mid.individual.net>
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:cIOEcXapNIq2WuATtDFYOpXQEtpcE1OlUnn6peSKpG5sa38+2E6
wYftIU/n7QLQqS7qbE3jcTVRZEUz45pQyZ7j0Yp/G4pr0XbGhI/EVdzBKzXwyUr6ZvI/WeD
7ESJxMeOFRVEsQouBfpiJuefqJwaG9+AHZAwKdfWLRYpWFBEa77UzLpsot8bx+iIEMNvF+v
yRDPcEJ5JbfqIxiFnapLA==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:HgKkiXvi0Ww=;m1lnj75IDhd6TZz81ccYNsNOsN1
D6x8nZT2Oxtarg1DTg6EZPMA9n9+hIOegFOasl9o0VrfCXVrroy49IwI2sRyOjrPkLBdF1H36
1j1rl52SUPaW4iDYuQrjJNRksQXQIm+A++MylKdQZhs65LB09ySbD1oGLAFbnc7fErL/HS1h7
LFv3TOXNylYVo4VBInRc6pzyPjuNxioXfIIMiqlI5fYw4tpZl1UdWfhK1eTXJcgWmGuEyEVfI
NtSs5KGAm0mietra59S53btQoMEVskOZ4kuBsNNGKPClnTbTMjfo5yfhicfZbgbrnQMnO/9Cn
yMbVwxzRTwxdORci+wyks+/h2E+TnwcPUUJn6UgU4eDTOkkjbjTGQTfIMsfqBK4ZdsCYZzm8J
dk3xKKxyXAOWyR5Vgz76T5K7hH652lxiML0VdamOCRVo9BORqMUBnHX/EXPFo2mEOqagK4Dlp
h0AyAIrKFr5nspSbRdkKudAO1CMpJRixGn1yW2joPjeS6VV22DmxFAQIWuG0dPaN5DyBjZJSV
hsDKzfqYOzHk8ziCWcW0iANETnblmyK28O6pYavx/PwIXIgO7fe8b7tcna1uS+LnRNIX8DB3i
t6a+qQfDCNcJgr8tTBSlx3WCwZ7miFDrtNbWHZ8578Y7su8eBfr81JyHIjid0aNc4E4TuKncX
72B5b8O11yEMLw/Kz8BQA26BFP7WULt+nYAZVUDTKx8JFrv2RWrJ4w8deDTuy9gTxuBLpypj2
LKcccjkafy1YtIUugkjSid0xqv1g2l+GE887mmfgMbVi+5OQCfxEEJAjRowmzdpW4p+hm3CjE
kl4lmnCVExWpSMdv4UiFn2Zr+DPrKbwi9Ucc09LMpqN0yM34XNKIlAKrXA18QkKD7x9N86lis
src3+Tb16KqBjCdA2862Y/vFTDn34H3jfzCG53nI9A4G+uoseIKaLfF1sCioRbTkD8sYcv8f9
bAqqmuFsEpGKhSgdm6zmhGJ9Wgo=
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: <ZZFxeIieVPI9jNI2@hermes.hilbert.loc>
X-Mailman-Original-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>
<04fd6edd-d6f3-43b6-9b5a-f279c34e1724@tompassin.net>
<mailman.100.1703971521.2892.python-list@python.org>
<kvbqnmF3cpkU2@mid.individual.net>
 by: Karsten Hilbert - Sun, 31 Dec 2023 13:49 UTC

Thanks to all. I ended up using Sequence for the list part
and Mapping for the dict part, which does require "import
typing" which I would rather have avoided.

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