Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Power corrupts. And atomic power corrupts atomically.


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

SubjectAuthor
o Aw: Re: mypy questionKarsten Hilbert

1
Aw: Re: mypy question

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

  copy mid

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

  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....@gmx.net (Karsten Hilbert)
Newsgroups: comp.lang.python
Subject: Aw: Re: mypy question
Date: Sat, 30 Dec 2023 16:08:27 +0100
Lines: 61
Message-ID: <mailman.92.1703948908.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>
<trinity-0dd8a644-4582-4c0c-a73e-4de250802749-1703948907120@3c-app-gmx-bap02>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: news.uni-berlin.de FEUYU23EPejVYerjX05fgwUWXbVCelVtXE/igEb6TItQ==
Cancel-Lock: sha1:9LUw8QmUlIz/NadnXGwqoG7BcWM= sha256:mosIk6XhyVKkfYMTfuuJdmdPH4khO93gUj0xJ2JjKgY=
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=BWG+MrAJ; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.015
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'issue.': 0.05;
'received:212.227': 0.07; 'string': 0.07; 'cc:addr:python-list':
0.09; 'karsten': 0.09; 'reasoning': 0.09; 'cc:no real name:2**0':
0.14; 'arguments': 0.16; 'dict': 0.16; 'dicts': 0.16; 'grasp':
0.16; 'hints': 0.16; 'received:(via http)': 0.16; 'skip:. 20':
0.16; 'str.': 0.16; 'python': 0.16; 'subject:question': 0.17;
'values': 0.17; 'cc:addr:python.org': 0.20; 'first,': 0.22;
'maybe': 0.22; 'run': 0.23; 'cc:2**0': 0.25; 'function': 0.27;
'simple,': 0.32; 'header:In-Reply-To:1': 0.34; 'complex': 0.35;
'respect': 0.35; 'thanks': 0.38; 'least': 0.39; 'list': 0.39;
'explain': 0.40; 'want': 0.40; 'should': 0.40; 'helps': 0.60;
'to:none': 0.60; 'above': 0.62; 'dear': 0.62; 'received:212':
0.62; 'complete': 0.64; 'look': 0.65; 'now,': 0.67;
'received:217': 0.67; 'further': 0.69; 'types,': 0.69; 'queries':
0.81; 'chose': 0.84; 'skip:q 20': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=s31663417; t=1703948907; x=1704553707; i=karsten.hilbert@gmx.net;
bh=4rdHLIpk5HgQ1deuJpDs/ecWavMIiyPkwJmSWCrNbUQ=;
h=X-UI-Sender-Class:From:Cc:Subject:Date:In-Reply-To:References;
b=BWG+MrAJ1FycjxPSBa6bm1pVvAcrpbXqvE3PQGZ8529RdYbzi/l+1NiQ5gN87/W0
NMJkqQUyHjwpyA3+IX7owJSUQcaav79amr0WaA+SvsisX8OY2leYuA5v6YmI/pGYO
vcewsLcOSU6kG8cMr0arV9lJLAexoPvGzqD1fu7uRrn2URNwEWkoCb4euzX1ytDb7
8K9U1J4PmBodYtSk9IWY7asMAIDEFEYe6fCgiZfj3UR8DwSvETyg1f2pGE2UHIl2o
JLbLVHYOdsXHzGYk6iKQeQ29Y3v7DmflwOcIEKhV5cgkd9/KSRPoT9ytLWZ8aGbaQ
1B/qG4d6QFjpji7o6A==
X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a
Importance: normal
Sensitivity: Normal
In-Reply-To: <1d9aa14c-fd26-4afd-b2fc-a9e516878491@tompassin.net>
X-UI-Message-Type: mail
X-Priority: 3
X-Provags-ID: V03:K1:9+C8Z/0bz9PoBjXq3PrHBc2tt0BC1O30yX0TF0hvT1UJYr3htzHqhK5ScOtNRZ3FV4EEv
Ou9NbBG4fjMzh/0VjGX4cyKDQ2OQBfgkmn0ENIOXYMntJv7eC3EqUrlba89CIr8VhBgfQS1LCseo
Z+zH6qEFkJnqV5zq6m95diSqdkxPPriQz4SfZhCeyM8P0nObv/yklPo3qgIvh6uq1Uxqg4+WIPKZ
C2Vj7Vvz2v0mYXgOWykB4HJrgWZ7R+qKoIj5g8Wb81TBf/9RhjiC7d0xM5YrSJVoaQW9sDbuzdPX
kM=
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:4oa5olzwObA=;jonMQV4M+SVHgGYv6SNjWQP729m
KN34uGo1iSVPdLG0cIwPIEwYzne6+9NI61Nygj5CrW58KHSbvFqwq5TPLsfVfFUdTt4tTtvIs
IIvrOOPC/qyQYKg8rH95nhbiHSLg7jsw2vRjqhroef2R6Duphwrmsue1qxSMV9CUk/H37OCOE
ptlwgrM3azC6kyIDHhXcclSM9u2dh9P6kOUiJNO3nFb2A9Kt2mmLmY+hKOXe71fNXHBUCmrs8
hg3z/cqHwqZv+VpzaSXt8sP6KITPpnkZ9k/gCOg6WUQoP0ryw/Am5zQ3QIlQLhYVmJgRPFYIY
xRL51cd2FvBaviQet58kx6kZEFNxMXJ1x053gaChQC8TjxHUzW5UZpobD03uapmge4OABWn/c
yP7VFysNSP63wNdeDr/wbCXyuQoYq5Vu2gMEG/cl80Blkspy12Xs0U7qisnxkxdCQnSOHMVfK
NMhBLUlkERr+dKHu4fZuRH9LUWBswsKO8pn3MEpkQhEV93M07RvU3PHt4CyvN+yHtA58tOq6t
YMBo+CboE4l/ORGxKxeoW1YvnA5AsMKFnhB5LAWDI1igFQ5CAP0mtKFCxYaX47VbKMxSLm46K
x0+tkwq8qOFwUMYABVjc3IjHvTfjrLt4myTu2Nx37W4LdPbJvNo5YjaU1fL6t4bfeXAkU3rgN
eSwtShssO3Vw8Jx5lIp+DG6Tw8eAUYCPqB/0qcssRiv3FpC8Af7go9McsJ1GuZTFnjhzltS4r
bu3uslJ5ShoHVTeOQq0vKDUI+nT/6ZtH9wOiVRbXdO7Z2vMtSoRU1rNmCMq1TlfkL16r3Eoum
NYih/7z3w+na0k7vKj+NaagA==
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: <trinity-0dd8a644-4582-4c0c-a73e-4de250802749-1703948907120@3c-app-gmx-bap02>
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: Karsten Hilbert - Sat, 30 Dec 2023 15:08 UTC

Dear Thomas,

thanks for taking the time to look into my issue.

Maybe it helps if I explain what I want (sorry that my web mailer does not respect
indentation, I will insert dots).

I want a function to run SQL queries:

run_queries(conn, queries):
....for q in queries:
.......conn.execute(q)

I now want to add type hints such that my large codebase can
be checked for silly doings. First, queries is to be a list
of the SQL to run:

run_queries(conn, queries:list):

Then, each list entry can be

....a string holding simple, complete SQL (say "SELECT 1")

run_queries(conn, queries:list[str]):

or

....a dict holding the SQL and arguments for parameters

run_queries(conn, queries:list[dict]):

So, taken together:

run_queries(conn, queries:list[str|dict]):

(yes, this is in Python 3.11/3.12)

Now, when it is a list of dicts I want to further constrain the
dicts. Each is to contain the keys "SQL" and "args". So the keys
are of type str. The values for the keys will be of various types,
such that I chose Any as pseudo-type, so that each list entry that
is of type dict should be dict[str, Any], hence:

queries = [{'SQL': 'SELECT %(value)s', 'args': {'value': 1}}]

and

run_queries(conn, queries:list[str|dict[str, Any]]):

If I now call this function with a simple SQL query:

SQL_query = 'SELECT 1' # should be type str ?
queries = [SQL_query] # should be type list[str] ?
run_queries(conn, queries = queries)

and run mypy over that (at least inside my complex codebase) I will
get a type mismatch being hinted at.

So far I don't grasp at which point my reasoning above is faulty.

Karsten

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor