4 ms·
> better type checking of C (over Python). Note that Python's official type checker (mypy) is pretty good (within the limits of type erasure); I started the pr
by i80and 7y ago
> better type checking of C (over Python).
Note that Python's official type checker (mypy) is pretty good (within the limits of type erasure); I started the project I've been leading up at work this past year in statically-typed Python, and it's been a great experience.
- linuxlizard 7y agoI haven't tried mypy yet but want to get to it. It sounds very interesting! After using Python so much the last several years, I've gotten more curmudgeonly about strong type checking in my programming languages.
- takeda 7y agoDon't wait for a new project, just start using it (is most beneficial if for every function you specify types for parameters and output). If you use an IDE that understand it like PyCharm, suddenly the autocomplete will start working right, so will refactoring and it will start highlighting potential errors.
- codr7 7y agoI 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.
- h8hawk 7y agoThey 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_CHECKING https://docs.python.org/3/library/typing.html#typing.TYPE_CH...
- weberc2 7y agoAlso 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.
- earthtolazlo 7y agoRecursive types were added in Typescript 3.7. Hopefully Python takes a page from their book.
- takeda 7y agoCan you show example? I believe you can use TypedDict to express that.
- weberc2 7y agoIt’s roughly JSON = Union[Dict[str, JSON], List[JSON], str, bool, int, NoneType] TypedDict isn’t for arbitrary JSON, but it is really cool.
- takeda 7y agoAh 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 https://github.com/python/mypy/issues/731 [2] https://github.com/python/mypy/issues/731#issuecomment-539905783 https://github.com/python/mypy/issues/731#issuecomment-53990... [3] https://gist.github.com/catb0t/bd82f7815b7e95b5dd3c3ad294f3cbbf https://gist.github.com/catb0t/bd82f7815b7e95b5dd3c3ad294f3c...
- Latty 7y agoI've played with mypy a little, and it's certainly not bad, but it does suffer by comparison to typescript, which just has a lot of really great structural typing features that mypy still lacks.
- Too 7y agomypy recently got structural typing. They call it Protocols, which isn't the first thing one one put into google when looking for this feature. It's not as powerful and terse as typescript unfortunately.