Skip to content

[suggest] Fix inference from collection literals #7979

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 2 commits into from
Nov 20, 2019
Merged

Conversation

msullivan
Copy link
Collaborator

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].

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]`.
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

I like this approach for inferring better suggestions. This should give a noticeable improvement in the precision of suggested types.

@@ -426,7 +430,7 @@ def get_suggestion(self, mod: str, node: FuncDef) -> PyAnnotateSignature:
callsites,
uses,
)
guesses = self.filter_options(guesses, is_method)
guesses = self.filter_options(guesses, is_method, ignore_return=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is the ignore_return=True change related to the rest of the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was abusing special_form because has_any_type didn't consider it an any. I didn't want to extend it to know about suggestion_engine also (and doing so would have interfered some with the use of suggestion_engine when refining)

@msullivan msullivan merged commit c39335a into master Nov 20, 2019
@msullivan msullivan deleted the suggest-inference branch November 20, 2019 21:06
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