{"action":"created","issue":{"url":"https://api.github.com/repos/python/typing/issues/238","repository_url":"https://api.github.com/repos/python/typing","labels_url":"https://api.github.com/repos/python/typing/issues/238/labels{/name}","comments_url":"https://api.github.com/repos/python/typing/issues/238/comments","events_url":"https://api.github.com/repos/python/typing/issues/238/events","html_url":"https://github.com/python/typing/issues/238","id":162065634,"number":238,"title":"Sequence example in List documentation does not typecheck","user":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-24T02:48:17Z","updated_at":"2016-06-27T17:13:24Z","closed_at":null,"body":"The [documentation for the `List` type][0] uses the following example to help demonstrate when to use `Sequence` vs `List`:\r\n\r\n```python\r\nT = TypeVar('T', int, float)\r\n\r\ndef vec2(x: T, y: T) -> List[T]:\r\n    return [x, y]\r\n\r\ndef slice__to_4(vector: Sequence[T]) -> List[T]:\r\n    return vector[0:4]\r\n```\r\n\r\nHowever, the `slice__to_4` function is does not actually typecheck since there's no guarantee that a slice of a sequence will return a `List` -- for example the vector could be a numpy array or a custom subclass of `collections.abc.Sequence` with an unusual `__getitem__`. Mypy correctly catches this error and complains about an \"Incompatible return value type\".\r\n\r\nThe documentation should probably be updated to use an example that _does_, though I'm not sure what exactly that example might look like? Maybe replace `slice__to_4` with something like this?\r\n\r\n```python\r\ndef keep_positives(vector: Sequence[T]) -> List[T]:\r\n    return [item for item in vector if item > 0]\r\n```\r\n\r\nPaging @gnprice, since he helped spot this.\r\n\r\n  [0]: https://docs.python.org/3/library/typing.html#typing.List"},"comment":{"url":"https://api.github.com/repos/python/typing/issues/comments/228810839","html_url":"https://github.com/python/typing/issues/238#issuecomment-228810839","issue_url":"https://api.github.com/repos/python/typing/issues/238","id":228810839,"user":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"created_at":"2016-06-27T17:13:24Z","updated_at":"2016-06-27T17:13:24Z","body":"I checked -- it doesn't look like PEP 484 has the bug. I refiled the bug report here: http://bugs.python.org/issue27402\r\n\r\nShould I close this issue?"}}
{"actor":{"display_login":"Michael0x2a"}}