News for hackers. Stuff that matters.
Re:I love coding in C by codr7 on Thursday December 26, 2019 @10:33AM (#21884448)
I tried to like mypy, really did. But it always ended up in some kind of circular import tailspin for me. C++ gets around the problem by allowing separation of interface and implementation, Haskell by allowing circular imports. Maybe I missed something, maybe it's fixed by now, but that was my experience a couple of years ago.
Re:I love coding in C by h8hawk on Thursday December 26, 2019 @10:53AM (#21884610)
They made a flag TYPE_CHECKING to avoid circular import in type checking. Its ugly but works.

https://docs.python.org/3/library/typing.html#typing.TYPE_CH...

Re:I love coding in C by weberc2 on Thursday December 26, 2019 @11:24AM (#21884842)
Also the circular imports was the least of the problems I’ve run into with mypy. They still can’t model a JSON type because it is recursive.
Re:I love coding in C by earthtolazlo on Thursday December 26, 2019 @12:19PM (#21885213)
Recursive types were added in Typescript 3.7. Hopefully Python takes a page from their book.
Re:I love coding in C by takeda on Thursday December 26, 2019 @11:01PM (#21889062)
Can you show example? I believe you can use TypedDict to express that.
Re:I love coding in C by weberc2 on Thursday December 26, 2019 @11:39PM (#21889229)
It’s roughly

    JSON = Union[Dict[str, JSON], List[JSON], str, bool, int, NoneType]
TypedDict isn’t for arbitrary JSON, but it is really cool.
Re:I love coding in C by takeda on Friday December 27, 2019 @01:30AM (#21889617)
Ah I see, TypedDict won't be useful here.

Looks like there is a work in progress though[1] and people in the ticket provided some workarounds[2][3] for now.

[1] https://github.com/python/mypy/issues/731

[2] https://github.com/python/mypy/issues/731#issuecomment-53990...

[3] https://gist.github.com/catb0t/bd82f7815b7e95b5dd3c3ad294f3c...