-
-
Notifications
You must be signed in to change notification settings - Fork 143
Validate all values for csv.QUOTE #991
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
Conversation
I didn't consider the fact that this will fail in |
pandas-stubs/_typing.pyi
Outdated
@@ -738,7 +738,7 @@ JsonSeriesOrient: TypeAlias = Literal["split", "records", "index", "table"] | |||
TimestampConvention: TypeAlias = Literal["start", "end", "s", "e"] | |||
|
|||
CSVEngine: TypeAlias = Literal["c", "python", "pyarrow", "python-fwf"] | |||
CSVQuoting: TypeAlias = Literal[0, 1, 2, 3] | |||
CSVQuoting: TypeAlias = Literal[0, 1, 2, 3, 4, 5] |
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.
Can you change this to use the references to csv.MINIMAL
, csv.QUOTE_ALL
, etc., You can do tests on the python version in a stub, e.g.,
if sys.version_info >= (3, 12):
CSVQuoting: TypeAlias = Literal[csv.MINIMAL, #rest of values ]
else:
CSVQuoting: TypeAlias = Literal[csv.MINIMAL, #rest of values]
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.
Oh, so maybe we should use Union[csv.MINIMAL, csv.QUOTE, # rest of values]
instead.
Never mind, the type checkers still don't want to infer the Type at static time, and the only importable Type is just |
Yes, I see that. I tried some other ideas and they just didn't work. |
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.
Thanks @refack , especially for trying the various workarounds.
4 and 5 added in 3.12 (python/cpython/67230)
ref: https://docs.python.org/3/library/csv.html#csv.QUOTE_NOTNULL
ref: https://github.com/python/cpython/blob/a8bc03696c7c2c03e1d580633151ec7b850366f3/Modules/_csv.c#L88-L106
assert_type()
to assert the type of any return value