[Python-ideas] Semantics for type checking (was: What should a good type checker do?)

Koos Zevenhoven k7hoven at gmail.com
Sun Sep 4 07:06:38 EDT 2016


On Sun, Sep 4, 2016 at 4:20 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Sep 04, 2016 at 12:26:58AM +0300, Koos Zevenhoven wrote:
>> On Friday, while replying to a post on python-dev about PEP 526
>> (variable annotations), I ended up mentioning things that I think a
>> good type checker should do, which seem to differ from the general
>> understanding. The discussion should continue here, though, because
>> the aim of PEP 526 is not to define type-checking semantics.
>
> Why should it continue here? The semantics of a type-checker is not part
> of Python the language. This is "python-ideas", not "third-party-
> application-ideas". If this thread belongs anywhere, it is probably the
> code quality mailing list.
>

I don't think you can 100% separate type checking syntax and
semantics. We should try to imagine desired future semantics as well
as possible before making decisions about syntax.

> It is very likely that different linters and type-checkers will take
> different approaches. Some may infer more, some may infer less, and
> that's a good thing.

I agree that's likely, but I'm not sure that is ultimately a good
thing. Type-checking semantics affect the way you write code, so at
least you cannot fully separate writing code from the kind of type
checking you use. What should large code bases do? What if you use
different libraries that have been annotated for different semantics?

> Before arguing what a type-checker should or shouldn't do, perhaps we
> ought to look at what MyPy, PyLint, PyChecker, PyFlakes and Jedi already
> do. (Apologies if I have missed anyone's favourite linter/checker.)

Sure, arguments in any direction would be interesting.

> We
> should not try to specify the behaviour of the type-checker. Let the
> type-checkers compete in the wider Python eco-system and converge to
> best practice as found by experience, not because we declare by fiat
> that Thou Shalt Do It This Way.
>

I'm not looking to fix type-checker behavior now. I do hope that
convergence is not going to take forever.

-- Koos

>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/



-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +


More information about the Python-ideas mailing list