I know I’m late, but I came across this thread while searching for the best way to annotate iterables, and I want to respectfully disagree with this reasoning:
I don’t like the idea that we “should” be using any sort of editor in order to have a pleasant experience with core language features. That seems contrary to my experience with Python, which I find concise enough that I can comfortably write it in vanilla vi (although I do use an IDE sometimes). It’s a big reason I find the language more joyful than, say, Java, which is arduous to write without smart auto-completion. I also believe it’s part of what makes Python so accessible to new programmers.
I’ve been happy to see other common types, like list[T] and T|None, become annotatable without any imports. Why should collections.abc.Iterable[T] be any different?
I understand that iter[T] is not the right answer, but I have hard time believing that we can’t figure some way to allow devs to annotate iterables without importing from the standard library.
To annotate iterables, you would either need to use:
a new builtin, or
some new punctuation-annotation.
I don’t think new punctuation is going to be very popular. String annotations are bad for introspection and will hopefully be supplanted by PEP 649. So that leaves a new built-in. It’s very hard to add built-ins because it breaks existing code.
Fair opinion, but it is a common reply for feature requests like:
block comments (your editor should be able to add # to multiple lines.
bulk passing locals to a function f(a=a, b=b, c=c). Your editor should be able to fill in pairs of words.
Of course you’re right that it would be nice if you could program Python efficiently in notepad, for example. But making Python adapt to that has other costs. If you come up with something, definitely propose it
While thoughts may differ, I don’t see typing as a core feature anymore than say itertools or pathlib. Having to import some more advanced features is commonplace in Python, why should the more advanced features of typing be any different?
You’re right, typing isn’t exactly a core feature.
That said, I think OP said it best:
Whether or not typing is a core feature, lists can be generically annotated without importing anything, and iterables can’t, which softly nudges developers to use list even when collections.abc.Iterable would suffice (which, in my experience, is very often).
I’m not sure what the right solution is. I understand that adding an Iterable builtin solely for the purpose of type annotation would be unprecedented. I am interested in what punctuation could look like (before you scoff, consider that Python syntax is already steeped with the concept of iterables, including for..in and *), but I’m not familiar enough yet with the internals of annotations to make an informed proposal.