You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a confusing use of type in a code snippet for typing.Literal). Link to section. Here is the code snippet in question, reproduced here:
defvalidate_simple(data: Any) ->Literal[True]: # always returns True
...
typeMode=Literal['r', 'rb', 'w', 'wb']
defopen_helper(file: str, mode: Mode) ->str:
...
open_helper('/some/path', 'r') # Passes type checkopen_helper('/other/path', 'typo') # Error in type checker
Line 4 is the problematic one. At first when I saw this, I thought that maybe the type function can also serve as a keyword/statement, like the old print statement in python2. However, it throws a SyntaxError, as expected if type is only a function.
Re-writing it slightly, this code is actually runnable and checkable with mypy:
While I realize not all code snippets are meant to be executable, I think this one is confusing. If others agree, I'd be happy to write a PR with the updated snippet.
The text was updated successfully, but these errors were encountered:
Documentation
There is a confusing use of
type
in a code snippet fortyping.Literal
). Link to section. Here is the code snippet in question, reproduced here:Line 4 is the problematic one. At first when I saw this, I thought that maybe the
type
function can also serve as a keyword/statement, like the oldprint
statement in python2. However, it throws a SyntaxError, as expected iftype
is only a function.Re-writing it slightly, this code is actually runnable and checkable with mypy:
While I realize not all code snippets are meant to be executable, I think this one is confusing. If others agree, I'd be happy to write a PR with the updated snippet.
The text was updated successfully, but these errors were encountered: