We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
ast.literal_eval can only return Dict, Set, Tuple, int, str, bool, float, complex and None. However its return type is set as Any.
ast.literal_eval
Dict
Set
Tuple
int
str
bool
float
complex
None
Any
The problem with that type definition is that mypy (with warn_return_any) complains when you compare against Any, and the following code:
warn_return_any
def comparator(value: str) -> bool: return ast.literal_eval(value) == expected_value
raises
Returning Any from function declared to return "bool"
The text was updated successfully, but these errors were encountered:
Generally speaking, Union return types are problematic. For more discussion, see https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions I don't think literal_eval is an exception here, anecdotally and based on https://grep.app/search?q=literal_eval%28&filter[lang][0]=Python
literal_eval
Sorry, something went wrong.
Another example where something like python/typing#566 could help, but at the moment there is not much we can do in typeshed, unfortunately.
No branches or pull requests
ast.literal_eval
can only returnDict
,Set
,Tuple
,int
,str
,bool
,float
,complex
andNone
. However its return type is set asAny
.The problem with that type definition is that mypy (with
warn_return_any
) complains when you compare againstAny
, and the following code:raises
The text was updated successfully, but these errors were encountered: