On Thu, 25 Nov 2021 at 21:45, Christopher Barker <python...@gmail.com> wrote: > The issue is that, intended or not, typing is making it's way into Python > culture. As an instructor of beginning python users, I am unsure at this > point when to introduce type annotations. > > What is their role? Up to today, I have treated them as an advanced feature, > useful for "complex codebases". But there are any number of examples > springing up on the internet, to the point where many students now think they > are "best practice", if not actually required.
Agreed this is somewhat OT, but I also think the messaging around annotations needs to be reviewed. I suspect that students will also not clearly understand the fact that annotations aren't checked at runtime. And IMO this is particularly difficult to get across in the case of non-typechecker uses of annotations. The following, for example, is extremely non-intuitive to me: >>> from dataclasses import dataclass >>> >>> @dataclass ... class A: ... n: int ... >>> a = A("didn't expect this!") >>> a A(n="didn't expect this!") Even though the "typing is optional" message is well-understood, my instincts still lead me to expect that declaring the type of n will result in a runtime type-check, in the constructor at least. (If I check the code with mypy, it does raise an error, so that's good. Although the more I think about it, given that I believe dataclasses use eval "under the hood", the less I understand *how* it manages to do that without special-case knowledge of the dataclass decorator...) I'd like to see a clearer statement from "somewhere" about how APIs should use annotations at runtime, such that Python users have a much clearer intuition about APIs like the dataclass one, and library designers can build their APIs based on a clear "common understanding" of what to expect when annotations are used. Paul _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/NBE7YL6EBVBB3NQ33DJI4KY3NSYL2Q5W/ Code of Conduct: http://python.org/psf/codeofconduct/