Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotation in for-loops #86233

Closed
gaaartner mannequin opened this issue Oct 18, 2020 · 5 comments
Closed

Type annotation in for-loops #86233

gaaartner mannequin opened this issue Oct 18, 2020 · 5 comments
Labels
3.9 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@gaaartner
Copy link
Mannequin

gaaartner mannequin commented Oct 18, 2020

BPO 42067
Nosy @markshannon, @pablogsal, @Fidget-Spinner

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-05-04.15:12:14.206>
created_at = <Date 2020-10-18.12:57:26.249>
labels = ['type-bug', '3.9']
title = 'Type annotation in for-loops'
updated_at = <Date 2021-05-04.15:12:14.205>
user = 'https://bugs.python.org/gaaartner'

bugs.python.org fields:

activity = <Date 2021-05-04.15:12:14.205>
actor = 'kj'
assignee = 'none'
closed = True
closed_date = <Date 2021-05-04.15:12:14.206>
closer = 'kj'
components = []
creation = <Date 2020-10-18.12:57:26.249>
creator = 'gaaartner'
dependencies = []
files = []
hgrepos = []
issue_num = 42067
keywords = []
message_count = 5.0
messages = ['378859', '378865', '392902', '392903', '392909']
nosy_count = 4.0
nosy_names = ['Mark.Shannon', 'pablogsal', 'kj', 'gaaartner']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42067'
versions = ['Python 3.9']

@gaaartner
Copy link
Mannequin Author

gaaartner mannequin commented Oct 18, 2020

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)

@gaaartner gaaartner mannequin added build The build process and cross-build 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Oct 18, 2020
@Fidget-Spinner
Copy link
Member

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).

@Fidget-Spinner
Copy link
Member

@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?

@markshannon
Copy link
Member

Definitely one for Python ideas.
Quite a good idea though.

@Fidget-Spinner
Copy link
Member

Thanks for your input Mark!

@Fidget-Spinner Fidget-Spinner removed the build The build process and cross-build label May 4, 2021
@Fidget-Spinner Fidget-Spinner removed the build The build process and cross-build label May 4, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants