-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
wrong types for csv.DictWriter #4800
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
Comments
The dict keys can be any type compatible with
This typevar can be for example I guess |
Awesome! I will take a stab at implementing this |
Actually, it accepts any type, because the underlying >>> import csv, enum, sys
>>> class Foo(enum.Enum):
... X=1
... Y=2
...
>>> w=csv.DictWriter(sys.stdout, list(Foo))
>>> w.writeheader()
Foo.X,Foo.Y
>>> w.writerow({Foo.X: "lol", Foo.Y: "wat"})
lol,wat
9 In your case, you needed |
Hi, it seems that
csv.DictWriter
is assuming dictionary keys will always be stringsI've found it useful to use IntEnum keys with DictWriter to avoid having magic strings and write metadata rows positionally
I think it would make sense to change csv.pyi to change
fieldnames
and the key of_DictRow
to be parameterize around aTypeVar('T')
I can add a pull request if you all think this is the right way to go
mypy ouput:
This is on Python 3.8.0 with mypy 0.790
The text was updated successfully, but these errors were encountered: