[PATCH 05 of 23 yams] [mypy] type __init__.py and add types.py

Laurent Peuch cortex at worlddomination.be
Wed Feb 26 19:15:51 CET 2020


On Wed, Feb 26, 2020 at 02:54:16PM +0100, Laurent Peuch wrote:
> On Wed, Feb 26, 2020 at 09:32:23AM +0100, Nicolas Chauvat wrote:
> > Hi Laurent,
> > 
> > On Tue, Feb 25, 2020 at 11:27:44PM +0100, Laurent Peuch wrote:
> > 
> > > > Also, you can take a look at TypedDict which seems to be appropriate to type
> > > > this kind of values:
> > > > https://mypy.readthedocs.io/en/latest/more_types.html#id3
> > > > (this is only available since python3.8 but there is a backport in the
> > > > typing-extensions package).
> > > 
> > > So I've actually explored a bit this option before realising that it
> > > won't work here :/ Why? Because, as quote from the documentation:
> > > 
> > > > Mypy will also reject a runtime-computed expression as a key, as it
> > > > can’t verify that it’s a valid key. You can only use string literals
> > > > as TypedDict keys.
> > 
> > Would using https://pyre-check.org/ remove that limitation ?
> > 
> > I suppose it won't, but did you try pyre anyway to compare its results with mypy ?
> 
> I wasn't aware of this program, thx for the hint!
> 
> I don't think it will (typed dictionary really seems bleeding edge
> right now) but I've gave it a try and well, yams won apparently:
> 
> > ƛ Client exited with error code 1:
> > Exception: Stack overflow
> 
> Full trace:
> 
> > (yams) psychojoker at incubus ~/code/yunohost/ynh-dev/logilab/yams/yams(virtualbox↓4|) pyre --source-directory . check
> >  Setting up a `.pyre_configuration` with `pyre init` may reduce overhead.
> >  ƛ Client exited with error code 1:
> >  Exception: Stack overflow
> >  Potential backtrace:
> >  Raised by primitive operation at file "hashtbl.ml", line 196,
> >  characters 9-23
> >  Called from file "hack_parallel/hack_parallel/heap/sharedMem.ml",
> >  line 1075, characters 15-35
> >  Worker exited (code: 2)
> >  Exception: Stack overflow
> >  Potential backtrace:
> >  Raised by primitive operation at file "hashtbl.ml", line 196,
> >  characters 9-23
> >  Called from file "hack_parallel/hack_parallel/heap/sharedMem.ml",
> >  line 1075, characters 15-35
> >  Worker exited (code: 2)
> 
> I guess it's report-a-bug time.

Except I've finally managed to make it work will trying to reproduce,
I'm pretty sure it was parsing some version of .mypy_cache or .pytype
directory but I really can't reproduce it.

The documentation doesn't say anything about it but it seems that they
are supporting TypeDict according to their tests
https://github.com/facebook/pyre-check/blob/60e89bc81c62f95a9436388f1b1f2561578a07e5/client/tests/apply_annotations_test.py#L632
https://github.com/facebook/pyre-check/blob/c8b51508f7f48218bb031ff92f2ccb1ad47914c1/analysis/test/integration/typedDictionaryTest.ml#L18

And I don't get the errors that mypy is raising regarding TypedDict
but it looks like it's because it doesn't handle it? When I'm putting
garbage instead of a variable name pyre doesn't complains so it might
be ignoring it?

In any case, pyre brings some new errors that mypy didn't brought so
it's a win in the end nevertheless!

I'll still probably need to drop TypedDict usage for now.

-- 

Laurent Peuch -- Bram



More information about the cubicweb-devel mailing list