This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Type annotation in for-loops
Type: behavior Stage: resolved
Components: Versions: Python 3.9
process
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 2022-04-11 14:59 by admin. 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
            process(element)
And can't do this:
        for element: ElementType  in my_list:
            process(element)
msg378865 - (view) Author: Ken Jin (kj) * (Python committer) 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:
       process(element)

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 committer) 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 https://discuss.python.org/c/ideas/ or https://mail.python.org/mailman3/lists/python-ideas.python.org/ 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 committer) Date: 2021-05-04 15:12
Thanks for your input Mark!
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86233
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