Skip to content

Conversation

@diego-plan9
Copy link
Contributor

Related to #40397

Summary

Inspired by ezyang's comment at #40397 (comment), this PR attempts to leverage using __all__ to explicitly export private functions from _VariableFunctions.pyi in order to make mypy aware of them after:

if False:
    from torch._C._VariableFunctions import *

The generation of the __all__ template variable excludes some items from unsorted_function_hints, as it seems that those without hints end up not being explicitly included in the .pyi file: I leaned on the side of caution and opted for having __all__ consistent with the definitions inside the file. Additionally, added some pretty-printing to avoid having an extremely long line.

Add a template variable that contains the names of the typed functions
and the named tuples during .pyi generation, appending it as the
`__all__` attribute of `_VariableFunctions.pyi`.
@gchanan gchanan requested a review from ezyang June 25, 2020 17:10
@gchanan gchanan added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 25, 2020
@ezyang
Copy link
Contributor

ezyang commented Jun 25, 2020

Can you paste the generated output? Looks good!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@ezyang merged this pull request in e180ca6.

@diego-plan9
Copy link
Contributor Author

Can you paste the generated output? Looks good!

Probably a bit late, but for reference, this is the bit that gets appended to the bottom of _variableFunctions.pyi (manually edited for brevity):

__all__ = ['__and__', '__lshift__', '__or__', '__rshift__', '__xor__', '_adaptive_avg_pool2d', '_addmv_impl_',
 '_addr', '_addr_', '_amp_non_finite_check_and_unscale_', '_amp_update_scale', '_baddbmm_mkl_',
...
 'true_divide', 'trunc', 'trunc_', 'unbind', 'unique_dim', 'unsqueeze', 'vander', 'var', 'var_mean',
 'view_as_complex', 'view_as_real', 'where', 'zero_', 'zeros', 'zeros_like']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants