Skip to content

Conversation

@driazati
Copy link
Contributor

@driazati driazati commented Jun 10, 2019

Class member annotations can be marked with Final[T] instead of adding them to __constants__. Final comes from the typing_extensions module (which will be used if it is present). If not, the polyfill from _jit_internal is exposed as torch.jit.Final for users that don't want to install typing_extensions.

This keeps around __constants__ since a lot of code is still using it, but in documentation follow ups we should change the examples to all to use Final.

TODO: install typing_extensions on CI, move tests to a Python3 only file when #21489 lands

Differential Revision: D15746274

Class member annotations can be marked with `Final[T]` instead of adding
them to `__constants__`. `Final` comes from the `typing_extensions`
module (which will be used if it is present). If not, the polyfill from
`_jit_internal` is exposed as `torch.jit.Final` for users that don't
want to install `typing_extensions`.

This keeps around `__constants__` since a lot
of code is still using it, but in documentation follow ups we should
change it all to use `Final`.
@pytorchbot pytorchbot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jun 10, 2019
@driazati driazati requested review from eellison and suo June 10, 2019 20:24
davidriazati added 2 commits June 12, 2019 12:58
@unittest.skipIf(PY2, "Class annotations are a thing in > 3.5")
def test_constants_with_final(self):
class M(torch.nn.Module):
# TODO: Use this (see below)
Copy link
Member

Choose a reason for hiding this comment

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

what's the deal with these TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is Python 3 only syntax, including it in this test makes all the Python2 tests fail to parse the file

@facebook-github-bot
Copy link
Contributor

@driazati merged this pull request in 0293cf5.

@facebook-github-bot facebook-github-bot deleted the driazati/final branch July 13, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants