Skip to content

Conversation

@elazarg
Copy link
Contributor

@elazarg elazarg commented Oct 27, 2016

Part of #2272.

The only place where the number of type arguments in type application might not match is when the user does that; this is explicitly checked in visit_type_application. Other places involve type inference, which must be correct "by construction" and if it isn't, that's a bug we want to catch, instead of returning AnyType.

It also allows us to remove casts.

cc @ddfisher

msg = messages.temp_message_builder()
applied = mypy.applytype.apply_generic_arguments(type, inferred_vars, msg, context=target)
if msg.is_errors() or not isinstance(applied, CallableType):
if msg.is_errors():
Copy link
Contributor Author

@elazarg elazarg Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps msg.is_errors() should be an assertion too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it, unless you can prove that apply_generic_arguments() cannot produce any errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely can produce errors, since it checks type variable bounds/allowed values.

'def (int) -> int'.
Note that each type can be None; in this case, it will not be applied.
Can only be None when len(tvars) != len(types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's outdated. Thanks.

Note that each type can be None; in this case, it will not be applied.
Can only be None when len(tvars) != len(types)
"""
assert len(callable.variables) == len(types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move the assert after the assignment.

Note that each type can be None; in this case, it will not be applied.
Can only be None when len(tvars) != len(types)
"""
assert len(callable.variables) == len(types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move the assert after the assignment.

@gvanrossum gvanrossum merged commit 6998787 into python:master Oct 27, 2016
@gvanrossum
Copy link
Member

Thanks!

@elazarg elazarg deleted the assert_apply_generics branch October 27, 2016 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants