Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

inirudebwoy
Copy link
Owner

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

msullivan and others added 2 commits December 11, 2017 16:53
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
Copy link
Owner Author

@inirudebwoy inirudebwoy left a 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([]))
Copy link
Owner Author

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

Copy link
Owner Author

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?
Copy link
Owner Author

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)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Silly things 🍌

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.

2 participants