Re: mypy question

2024-01-13 Thread Karsten Hilbert via Python-list
%s', 'args': [1] }, { 'SQL': 'SELECT %(value)s', 'args': {'value': 1} } ] The value for key "SQL" will always be str-like. The value for "args" can

Re: mypy question

2024-01-13 Thread Karsten Hilbert via Python-list
Am Fri, Jan 12, 2024 at 02:23:43PM +0100 schrieb Antoon Pardon via Python-list: > > 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, > >s

Re: mypy question

2024-01-12 Thread Antoon Pardon via Python-list
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

Re: mypy question

2023-12-31 Thread Karsten Hilbert via Python-list
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 -- https://mail.python.org/mailman/listinfo/python-list

Re: mypy question

2023-12-30 Thread Greg Ewing via Python-list
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 t

Re: Aw: Re: mypy question

2023-12-30 Thread Greg Ewing via Python-list
On 31/12/23 8:05 am, Chris Angelico wrote: Ah, I think you've hit on the problem there. Consider this: def add_item(stuff: dict[str: str | int]): stuff["spam"] = "ham" stuff["vooom"] = 1_000_000 Yep, that's it exactly. It's not the union itself that's the problem, but the fact that t

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
t[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

Re: Aw: Re: mypy question

2023-12-30 Thread Chris Angelico via Python-list
On Sun, 31 Dec 2023 at 03:38, Thomas Passin via Python-list wrote: > I am not very expert in Python type hints. In working up the example > program I just posted, I got an error message from mypy that remarked > that "list" is invariant, and to try Sequence which is "cov

Re: mypy question

2023-12-30 Thread Barry via Python-list
> On 30 Dec 2023, at 15:11, Karsten Hilbert via Python-list > wrote: > > queries = [{'SQL': 'SELECT %(value)s', 'args': {'value': 1}}] > > and > > run_queries(conn, queries:list[str|dict[str, Any]]): In cases like this I often use a wrapper class in place of a simple str. If you have a cla

Aw: Re: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
> I'm fairly sure your database queries don't actually give you strings or > dicts, right? You probably get lists (or iterators) of tuples and > somewhere you convert them to the arguments you are feeding to > run_queries(). Ah, no, those queries are enshrined within the middleware as Python stri

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote: 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[D

Aw: Re: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
ll take it as an opportunity to refactor them. So, at least that much good has come from the mypy hint ;-) Karsten -- https://mail.python.org/mailman/listinfo/python-list

Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
# 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 -- https://mail.python.org/mailman/listinfo/python-list

Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
ry] # 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 I am not very expert in Python type

Aw: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
27;, '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 = q

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
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 cause

Aw: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
Python at hand currently, so I'll write untested pseudocode: def print_greeting(greeting:int|str): print(greeting) print_greeting('hello') The above snippet should be equivalent to my more complicated code over which mypy complains to the equivalent of "input" is of

Re: mypy question

2023-12-29 Thread Greg Ewing via Python-list
type safe. dict[str, str] is not a subtype of dict[str, str | something_else] because you can assign a value of type something_else to the latter but not the former. In this case it happens to be okay because the function is (presumably) treating the dict passed in as immutable, but MyPy has no

Re: mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
> >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

Re: mypy question

2023-12-29 Thread Mats Wichmann via Python-list
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'

Re: mypy question

2023-12-29 Thread 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]]"; expe

Re: mypy question

2023-12-29 Thread Mats Wichmann via Python-list
On 12/29/23 05:15, Karsten Hilbert via Python-list wrote: Hi all, 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[

Re: mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Am Fri, Dec 29, 2023 at 01:15:29PM +0100 schrieb Karsten Hilbert 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 > "

mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Hi all, 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] ro

Re: is mypy failing here

2022-11-25 Thread Thomas Passin
On 11/25/2022 12:00 PM, Robin Becker wrote: On 24/11/2022 14:10, Thomas Passin wrote: . C:\temp\python>py -V Python 3.10.4 C:\temp\python>py tdc.py DC(a=, b='B') C:\temp\python>mypy tdc.py tdc.py:10: error: Argument 1 to "DC" has incompatible ty

Re: is mypy failing here

2022-11-25 Thread Robin Becker
On 24/11/2022 13:50, Kirill Ratkin via Python-list wrote: mypy --strict gives you detail info. Thanks Kirill, it seems --strict does find the errors. One of those is that on line 9 I have to add a return type ie def main() -> None: . if that is added then mypy without --strict a

Re: is mypy failing here

2022-11-25 Thread Robin Becker
On 24/11/2022 14:10, Thomas Passin wrote: . C:\temp\python>py -V Python 3.10.4 C:\temp\python>py tdc.py DC(a=, b='B') C:\temp\python>mypy tdc.py tdc.py:10: error: Argument 1 to "DC" has incompatible type "Type[DC]"; expected "str&quo

Re: is mypy failing here

2022-11-24 Thread Kirill Ratkin via Python-list
Hi Robin, mypy --strict gives you detail info. On Thu, Nov 24, 2022 at 10:05 +, Robin Becker wrote: > I haven't used dataclasses or typing very much, but while playing about I > found this didn't give me an expected error > > (.py312) robin@minikat:~/devel/reportla

Re: is mypy failing here

2022-11-24 Thread Thomas Passin
p;& python tmp/examples/tdc.py && mypy tmp/examples/tdc.py ## from dataclasses import dataclass @dataclass class DC: a: str b: str def main(): dc = DC(DC, "B") print(dc) if __name__ == "__main__": main() ##

Re: is mypy failing here

2022-11-24 Thread Weatherby,Gerard
https://github.com/python/mypy/issues/12971 From: Python-list on behalf of Thomas Passin Date: Thursday, November 24, 2022 at 7:36 AM To: python-list@python.org Subject: Re: is mypy failing here *** Attention: This is an external email. Use caution responding, opening attachments or clicking

Re: is mypy failing here

2022-11-24 Thread Thomas Passin
On 11/24/2022 5:05 AM, Robin Becker wrote: I haven't used dataclasses or typing very much, but while playing about I found this didn't give me an expected error (.py312) robin@minikat:~/devel/reportlab $ cat tmp/examples/tdc.py && python tmp/examples/tdc.py &&

is mypy failing here

2022-11-24 Thread Robin Becker
I haven't used dataclasses or typing very much, but while playing about I found this didn't give me an expected error (.py312) robin@minikat:~/devel/reportlab $ cat tmp/examples/tdc.py && python tmp/examples/tdc.py && mypy tmp/examples/tdc.py #

Mypy alternatives

2022-05-14 Thread Dan Stromberg
Hello people. I've used Mypy and liked it in combination with MonkeyType. I've heard there are alternatives to Mypy that are faster, and I'm looking at using something like this on a 457,000 line project. Are there equivalents to MonkeyType that will work with these alternative

Re: How to make a type of a C extension compatible with mypy

2022-01-01 Thread Kirill Ratkin
// BR (KR) 01.01.2022 21:49, Marco Sulla пишет: I created a type in a C extension, that is an immutable dict. If I do: a: mydict[str, str] it works. But it doesn't work with mypy, as signalled to me by an user: https://github.com/Marco-Sulla/python-frozendict/issues/39 How can I make it wor

How to make a type of a C extension compatible with mypy

2022-01-01 Thread Marco Sulla
I created a type in a C extension, that is an immutable dict. If I do: a: mydict[str, str] it works. But it doesn't work with mypy, as signalled to me by an user: https://github.com/Marco-Sulla/python-frozendict/issues/39 How can I make it work? I don't know what he means with

PyLint and Mypy real-time (and on-demand) code inspection from within PyCharm/IDEA

2018-09-18 Thread Roberto Leinardi
Hello there, I am the developer of pylint-pycharm and mypy-pycharm, two plugins providing both real-time and on-demand scanning of Python files with PyLint/Mypy from within PyCharm/IDEA. The real-time code inspection works automatically the same way like the PyCharm's build-in PEP8 check

Dropbox releases PyAnnotate -- auto-generate type annotations for mypy

2017-11-16 Thread breamoreboy
As type annotations seem to be taking off in a big way I thought that http://mypy-lang.blogspot.co.uk/2017/11/dropbox-releases-pyannotate-auto.html would be of interest, to some of you anyway. -- Kindest regards. Mark Lawrence. -- https://mail.python.org/mailman/listinfo/python-list

Re: Mypy

2013-07-11 Thread Stefan Behnel
Fábio Santos, 11.07.2013 10:16: > Guido tweeted that yesterday. It seems interesting. Although I'm not > comfortable using a subset of the language. > > They seem to want to kill the GIL. This could get much more popular when > they do. Then don't forget to also take a look at Cython. Stefan -

Re: Mypy

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 09:08, "Steven D'Aprano" wrote: > > Things are certainly heating up in the alternate Python compiler field. > Mypy is a new, experimental, implementation of Python 3 with optional > static typing and aiming for efficient compilation to machine code. &

Mypy

2013-07-11 Thread Steven D'Aprano
Things are certainly heating up in the alternate Python compiler field. Mypy is a new, experimental, implementation of Python 3 with optional static typing and aiming for efficient compilation to machine code. http://www.mypy-lang.org/index.html -- Steven -- http://mail.python.org/mailman