-
Notifications
You must be signed in to change notification settings - Fork 0
Rework how we refine information from callable() #1
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
base: master
Are you sure you want to change the base?
Conversation
Don't ever assume that something is *not* callable; basically anything could be, and getting it wrong leaves code to not be typechecked. When operating on an Instance that is not clearly callable, construct a callable version of it by generating a fake subclass with a __call__ method to be used. Fixes python#3605
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.
fix it damn it
mypy/checker.py
Outdated
|
||
# Build the fake ClassDef and TypeInfo together. | ||
# The ClassDef is full of lies and doesn't actually contain a body. | ||
cdef = ClassDef("<callable subtype of {}>".format(type.type.name()), Block([])) |
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.
This is bad ⚰️ come on dude
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.
hmmm how do I close this?
callables.extend(subcallables) | ||
uncallables.extend(subuncallables) | ||
return callables, uncallables | ||
|
||
if isinstance(type, TypeVarType): | ||
return partition_by_callable(type.erase_to_union_or_bound()) | ||
# We could do better probably? |
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.
So loooong
left_if_vars, left_else_vars = find_isinstance_check(node.left, type_map) | ||
right_if_vars, right_else_vars = find_isinstance_check(node.right, type_map) | ||
left_if_vars, left_else_vars = find_isinstance_check(node.left, type_map, typechecker) | ||
right_if_vars, right_else_vars = find_isinstance_check(node.right, type_map, typechecker) |
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.
Silly things 🍌
Don't ever assume that something is not callable; basically anything
could be, and getting it wrong leaves code to not be typechecked.
When operating on an Instance that is not clearly callable, construct
a callable version of it by generating a fake subclass with a call
method to be used.
Fixes python#3605