New type inference: complete transitive closure by ilevkivskyi · Pull Request #15754 · python/mypy (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation7 Commits16 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

ilevkivskyi

This is a first follow-up for #15287 (I like how my PR titles sound like research paper titles, LOL)

This PR completes the new type inference foundations by switching to a complete and well founded algorithm [1] for transitive closure (that replaces more ad hoc initial algorithm that covered 80% of cases and was good for experimenting with new inference scheme). In particular the algorithm in this PR covers two important edge cases (see tests). Some comments:

[1] Definition 7.1 in https://inria.hal.science/inria-00073205/document

@ilevkivskyi

Btw I guess I should quote the thesis where I took the algorithm I am using here. I will update the PR description.

@github-actions

This comment has been minimized.

@ilevkivskyi

OK, I went through mypy_primer and I am generally happy, most of the output matches the previous PR. There are two differences:

@ilevkivskyi

@github-actions

This comment has been minimized.

@ilevkivskyi

All looks good, I will now switch the default back to false to prepare for merge.

@ilevkivskyi

@github-actions

Diff from mypy_primer, showing the effect of this PR on open source code:

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)

@ilevkivskyi

OK, it looks like no one is around to take a look at this. I have the next PR ready, so I am going to merge this tomorrow, unless there are objections.

ilevkivskyi added a commit that referenced this pull request

Aug 9, 2023

@ilevkivskyi

This is a third PR in series following #15287 and #15754. This one is quite simple: I just add basic support for polymorphic inference involving type variables with upper bounds and values. A complete support would be quite complicated, and it will be a corner case to already rare situation. Finally, it is written in a way that is easy to tune in the future.

I also use this PR to add some unit tests for all three PRs so far, other two PRs only added integration tests (and I clean up existing unit tests as well).

1 participant

@ilevkivskyi