Skip to content

[suggest] Fix inference of returned collection #7810

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

Merged
merged 1 commit into from
Oct 28, 2019
Merged

Conversation

msullivan
Copy link
Collaborator

Do this by suppressing the use of Any contexts, which cause arguments
to be misinferred. This can cause certain things to be inferred as
<nothing> instead of Any, but that's seems fine.

Do this by suppressing the use of Any contexts, which cause arguments
to be misinferred. This can cause certain things to be inferred as
`<nothing>` instead of `Any`, but that's seems fine.
# anys than we want for things that consume the inferred
# types.
if isinstance(get_proper_type(type_context), AnyType):
type_context = None
Copy link
Member

Choose a reason for hiding this comment

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

This may actually be a big change. I am curious how this behaves w.r.t. to things like

def foo(x: Any) -> None: ...
T = TypeVar('T', bound=int)
def g(x: T) -> T: # also -> Optional[T] and -> List[T], IIRC all three are special cased
    ...
foo(g('no'))

If these example don't change behaviour, then I think this is good to go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't seem to change anything there

@msullivan msullivan merged commit 766d58f into master Oct 28, 2019
@msullivan msullivan deleted the suggest-collections branch October 28, 2019 22:03
JukkaL added a commit that referenced this pull request Oct 30, 2019
JukkaL added a commit that referenced this pull request Oct 30, 2019
msullivan added a commit that referenced this pull request Nov 20, 2019
This is another take at #7810 which was reverted because it caused
internal trouble.

Do this by ignoring constraints with Any when the Any comes from the
suggestion engine. The Any context causes assigned types to be Any
overaggressively.  Restricting it only to Anys from the suggestion
engine avoids the issues seen last time. Doing it at a fine-grained
level in constraints allows us to do better refining things like `List[Any]`.
msullivan added a commit that referenced this pull request Nov 20, 2019
This is another take at #7810 which was reverted because it caused
internal trouble.

Do this by ignoring constraints with Any when the Any comes from the
suggestion engine. The Any context causes assigned types to be Any
overaggressively.  Restricting it only to Anys from the suggestion
engine avoids the issues seen last time. Doing it at a fine-grained
level in constraints allows us to do better refining things like `List[Any]`.
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy