This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author michael0x2a
Recipients docs@python, michael0x2a
Date 2016-06-27.17:09:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1467047380.43.0.562730585486.issue27402@psf.upfronthosting.co.za>
In-reply-to
Content
In the documentation for the `typing` module, the [entry for the `List` type][0] uses the following example to help demonstrate when to use `Sequence` vs `List`:

    T = TypeVar('T', int, float)

    def vec2(x: T, y: T) -> List[T]:
        return [x, y]

    def slice__to_4(vector: Sequence[T]) -> List[T]:
        return vector[0:4]

However, the `slice__to_4` function 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").

The documentation should probably be updated to use an example that _does_ typecheck, though I'm not sure what exactly that example might look like? Maybe replace `slice__to_4` with something like this?

    def keep_positives(vector: Sequence[T]) -> List[T]:
        return [item for item in vector if item > 0]
History
Date User Action Args
2016-06-27 17:09:40michael0x2asetrecipients: + michael0x2a, docs@python
2016-06-27 17:09:40michael0x2asetmessageid: <1467047380.43.0.562730585486.issue27402@psf.upfronthosting.co.za>
2016-06-27 17:09:40michael0x2alinkissue27402 messages
2016-06-27 17:09:39michael0x2acreate