Skip to content

Commit

Permalink
Fix method stub used for fixing mypy issue to work with pylint (pytor…
Browse files Browse the repository at this point in the history
…ch#42356)

Summary:
Make function from method

Since _forward_unimplemented is defined within the nn.Module class,
pylint (correctly) complains about not implementing this method in subclasses.

Fixes pytorch#42305

Pull Request resolved: pytorch#42356

Reviewed By: mruberry

Differential Revision: D22867255

Pulled By: ezyang

fbshipit-source-id: ccf3e45e359d927e010791fadf70b2ef231ddb0b
  • Loading branch information
mberr authored and facebook-github-bot committed Aug 6, 2020
1 parent 04d7e16 commit ddb8849
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions torch/nn/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ def register_module_backward_hook(
return handle


# Trick mypy into not applying contravariance rules to inputs by defining
# forward as a value, rather than a function. See also
# https://github.com/python/mypy/issues/8795
def _forward_unimplemented(self, *input: Any) -> None:
raise NotImplementedError


class Module:
r"""Base class for all neural network modules.
Expand Down Expand Up @@ -220,12 +227,6 @@ def __init__(self):
self._load_state_dict_pre_hooks = OrderedDict()
self._modules = OrderedDict()

# Trick mypy into not applying contravariance rules to inputs by defining
# forward as a value, rather than a function. See also
# https://github.com/python/mypy/issues/8795
def _forward_unimplemented(self, *input: Any) -> None:
raise NotImplementedError

r"""Defines the computation performed at every call.
Should be overridden by all subclasses.
Expand Down

0 comments on commit ddb8849

Please sign in to comment.