Repository: chainer/chainer

Issue:
Importing chainer fails on Python 3.5.1
This is a bug reported by @hvy. When importing the current `master` version of `chainer` (`070deb5`) on Python 3.5.1, it fails with `RuntimeError` because it uses [the older builtin `typing` module](https://github.com/mirumee/prices/issues/30#issuecomment-376200373) which doesn't support `@overload` annotation [outside a stub file](https://github.com/python/typing/issues/72).

```
$ python
Python 3.5.1 (default, Nov 15 2018, 17:50:51) 
[GCC 5.5.0 20171010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chainer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/chainer/chainer/__init__.py", line 18, in <module>
    from chainer import links  # NOQA
  File "/home/user/chainer/chainer/links/__init__.py", line 3, in <module>
    from chainer.links.activation.maxout import Maxout  # NOQA
  File "/home/user/chainer/chainer/links/activation/maxout.py", line 6, in <module>
    from chainer import link
  File "/home/user/chainer/chainer/link.py", line 1144, in <module>
    class ChainList(Link, collections_abc.MutableSequence):
  File "/home/user/chainer/chainer/link.py", line 1182, in ChainList
    @tp.overload  # NOQA
  File "/home/user/.pyenv/versions/3.5.1/lib/python3.5/typing.py", line 1184, in overload
    raise RuntimeError("Overloading is only supported in library stubs")
RuntimeError: Overloading is only supported in library stubs
```
Importing chainer fails on Python 3.5.1
This is a bug reported by @hvy. When importing the current `master` version of `chainer` (`070deb5`) on Python 3.5.1, it fails with `RuntimeError` because it uses [the older builtin `typing` module](https://github.com/mirumee/prices/issues/30#issuecomment-376200373) which doesn't support `@overload` annotation [outside a stub file](https://github.com/python/typing/issues/72).

```
$ python
Python 3.5.1 (default, Nov 15 2018, 17:50:51) 
[GCC 5.5.0 20171010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chainer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/chainer/chainer/__init__.py", line 18, in <module>
    from chainer import links  # NOQA
  File "/home/user/chainer/chainer/links/__init__.py", line 3, in <module>
    from chainer.links.activation.maxout import Maxout  # NOQA
  File "/home/user/chainer/chainer/links/activation/maxout.py", line 6, in <module>
    from chainer import link
  File "/home/user/chainer/chainer/link.py", line 1144, in <module>
    class ChainList(Link, collections_abc.MutableSequence):
  File "/home/user/chainer/chainer/link.py", line 1182, in ChainList
    @tp.overload  # NOQA
  File "/home/user/.pyenv/versions/3.5.1/lib/python3.5/typing.py", line 1184, in overload
    raise RuntimeError("Overloading is only supported in library stubs")
RuntimeError: Overloading is only supported in library stubs
```


Discussion:

Resolving patch:
diff --git a/chainer/link.py b/chainer/link.py
--- a/chainer/link.py
+++ b/chainer/link.py
@@ -1179,17 +1179,7 @@ def __setattr__(self, name, value):
                 ' within a "with chainlist.init_scope():" block.')
         super(ChainList, self).__setattr__(name, value)
 
-    @tp.overload  # NOQA
-    def __setitem__(self, key, value):
-        # type: (int, Link) -> None
-        pass
-
-    @tp.overload  # NOQA
-    def __setitem__(self, key, value):
-        # type: (slice, tp.Iterable[Link]) -> None
-        pass
-
-    def __setitem__(self, index, value):  # NOQA
+    def __setitem__(self, index, value):
         # type: (tp.Union[int, slice], tp.Union[Link, tp.Iterable[Link]]) -> None # NOQA
 
         if isinstance(index, int):
@@ -1205,18 +1195,7 @@ def __setitem__(self, index, value):  # NOQA
                 'ChainList indices must be integers or slices, not %s' %
                 type(index).__name__)
 
-    @tp.overload  # NOQA
-    def __getitem__(self, key):
-        # type: (int) -> Link
-        pass
-
-    @tp.overload  # NOQA
-    def __getitem__(self, key):
-        # type: (slice) -> collections_abc.MutableSequence[Link]
-        pass
-
-    def __getitem__(self, index):  # NOQA
-        # type: (tp.Union[int, slice]) -> tp.Union[Link, collections_abc.MutableSequence[Link]] # NOQA
+    def __getitem__(self, index):
         """Returns the child at given index.
 
         Args:


Test patch: