-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Relax DictWriter.fieldnames closer to implementation #5994
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
Relax DictWriter.fieldnames closer to implementation #5994
Conversation
I think this might actually work if you pass just an Iterable, however since that would allow passing a generator (which would definitely not work correctly) I've kept this as Collection. Fix python#5993
This comment has been minimized.
This comment has been minimized.
stdlib/csv.pyi
Outdated
@@ -17,7 +17,7 @@ from _csv import ( | |||
unregister_dialect as unregister_dialect, | |||
writer as writer, | |||
) | |||
from typing import Any, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, overload | |||
from typing import Any, Collection, Generic, Iterable, Iterator, Mapping, Sequence, Type, TypeVar, overload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor thing: We should import Collection
, Iterable
, Iterator
, Mapping
, and Sequence
from collections.abc
instead of typing
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, should that be changed here, or would it be preferable to do that separately? (I'd be happy to put together a subsequent PR which does these all together)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever works best for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f8af7bc hopefully fixes this.
Just a thought -- would it be useful to have a flake8 plugin (custom to this repo) which checked for this? I suspect it would be fairly easy to create one and might make this preference more visible. If I recall correctly no-one would need to install anything extra, it would just be a file somewhere in the repo and some configuration in the pyproject.toml
and flake8 would do the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also changing DictReader
, so that it is consistent with DictWriter
.
Hrm, I'd not spotted that you can pass fieldnames to However it's optional and you can omit them and get back a Additionally passing a value is complicated by the fact that it's the passed value you get back from It feels like the right signature for Very happy to be guided on how to spell the signature for |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Thanks! |
I think this might actually work if you pass just an
Iterable
, however since that would allow passing a generator (which would definitely not work correctly) I've kept this asCollection
.Fixes #5993