-
Notifications
You must be signed in to change notification settings - Fork 262
Prohibit Callable[[...], X] #320
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1221,9 +1221,9 @@ def __getitem__(self, parameters): | |
elif args == []: | ||
parameters = ((), result) | ||
else: | ||
if not isinstance(args, list): | ||
raise TypeError("Callable[args, result]: args must be a list." | ||
" Got %.100r." % (args,)) | ||
if not isinstance(args, list) or ... in args or () in args: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... It really shouldn't be necessary to check this here. I think the reason may be that you're trying to make the hash key for e.g. Or maybe you're trying to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gvanrossum Yes, indeed I wanted to flatten |
||
raise TypeError("Callable[args, result]: args must be" | ||
" a list of types. Got %.100r." % (args,)) | ||
parameters = tuple(args) + (result,) | ||
return self.__getitem_inner__(parameters) | ||
|
||
|
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.
I don't think you need this special case, and if you remove it and the matching special case in
__getitem_inner__
the tests still passes. (It's different here than for Tuple -- whileTuple[]
is invalid due to Python's syntax,Callable[[], t]
is fine, and there's no need to treat an empty list special.PS. I can't add a comment there, but your code below has
[...,]
and[(),]
-- those trailing commas are not needed.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.
@gvanrossum You are right, only ellipsis needs special case (in two places you mention, and also in
__repr__
).