Title: Type annotation in for-loops
Type: behavior Stage: resolved
Components: Versions: Python 3.9
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, gaaartner, kj, pablogsal
Priority: normal Keywords:

Created on 2020-10-18 12:57 by gaaartner, last changed 2021-05-04 15:12 by kj. This issue is now closed.

Messages (5)
msg378859 - (view) Author: barak dopama (gaaartner) Date: 2020-10-18 12:57
Why do I have to do this:
        for element in my_list:
            element: ElementType = element
And can't do this:
        for element: ElementType  in my_list:
msg378865 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2020-10-18 14:34
That's an interesting syntax suggestion, you might want to suggest that in the python-ideas mailing list for other people to read about it rather than post it on python bugs.

IMO, this isn't really an issue since you can specify the type of the elements in generic types via::

   my_list: list[int] = [1, 2, 3]
   for element in my_list:

Your type checker should be able to infer that ``element`` is of type ``int`` (or hopefully, it will in the near future).
msg392902 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-05-04 14:27
@pablo, may I close this issue as 'not a bug'? I think it looks like a feature request that belongs on or instead. What do you think?
msg392903 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-05-04 14:40
Definitely one for Python ideas.
Quite a good idea though.
msg392909 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-05-04 15:12
Thanks for your input Mark!
Date User Action Args
2021-05-04 15:12:14kjsetstatus: open -> closed
messages: + msg392909

components: - Build
resolution: rejected
stage: resolved
2021-05-04 14:40:32Mark.Shannonsetnosy: + Mark.Shannon
messages: + msg392903
2021-05-04 14:27:13kjsetnosy: + pablogsal
messages: + msg392902
2020-10-18 14:34:03kjsetnosy: + kj
messages: + msg378865
2020-10-18 12:57:26gaaartnercreate