Skip to content

Comments

Avoid unnecessary work when checking deferred functions#20860

Open
ilevkivskyi wants to merge 3 commits intopython:masterfrom
ilevkivskyi:fix-redefinition-deferral
Open

Avoid unnecessary work when checking deferred functions#20860
ilevkivskyi wants to merge 3 commits intopython:masterfrom
ilevkivskyi:fix-redefinition-deferral

Conversation

@ilevkivskyi
Copy link
Member

As I was looking more I noticed that we widen the inferred types during redefinition even if current function is deferred. It turned out that this doesn't seem to have any user visible effect (mostly because set_inferred_type() already guards against this). But we still do a bunch of pointless work (like few extra calls to make_simplified_union() per assignment), so we should bail out early.

But then I thought why do we even continuing to type-check the current function if:

  • We do not infer any variables
  • ExpressionChecker.accept() returns Any for every expression
  • We don't show any errors

If all tests pass, and there is nothing in primer, I think we should stop type-checking soon after deferral, as this will probably save ~1-2% of time (maybe more for code bases with many import cycles etc).

Added test already passes on master, I added it to avoid regressions as I didn't find any similar tests for --allow-redefinition-new.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

1 participant