-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Make type function return Type[T] #1787
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 2 commits
bb4b130
bc02605
3fd8d82
1c849da
2fd4f56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,11 @@ def check_call(self, callee: Type, args: List[Node], | |
self.check_argument_types(arg_types, arg_kinds, callee, | ||
formal_to_actual, context, | ||
messages=arg_messages) | ||
|
||
ret_val_is_type_obj = is_equivalent(callee.ret_type, self.named_type('builtins.type')) | ||
if callee.is_type_obj() and (len(arg_types) == 1) and ret_val_is_type_obj: | ||
callee.ret_type = TypeType(arg_types[0]) | ||
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. This seems fishy -- I wouldn't mutate callee, who knows if it's been shared elsewhere. I think the common pattern is to make a modified copy -- you can find examples of copy_modified() aplenty. 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. Done! I pushed an updated commit for both your comments. |
||
|
||
if callable_node: | ||
# Store the inferred callable type. | ||
self.chk.store_type(callable_node, callee) | ||
|
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.
That's a pretty expensive call, and this case rarely triggers, so the time is usually wasted. I suggest testing the simpler conditions first and doing this call last.