AndreaCensi / contracts

PyContracts is a Python package that allows to declare constraints on function parameters and return values. Contracts can be specified using Python3 annotations, or inside a docstring. PyContracts supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts and an extension API.
http://andreacensi.github.io/contracts/
Other
398 stars 62 forks source link

A set is considered to be a sequence #14

Closed beloglazov closed 11 years ago

beloglazov commented 11 years ago

Hi, I've just faced a problem that seq fails to match a set:

Expected a sequence, got 'set'. checking: seq for value: Instance of set: set(['\xa3\x9a\x05\x10\xa7l\xc61\x8e', '\xd... [clip]

Is it by design?

AndreaCensi commented 11 years ago

Yes.

from collections import Sequence
isinstance(set(), Sequence) # => False

See here for what Python means by "sequence" and others: http://docs.python.org/2/library/collections.html#collections-abstract-base-classes

Basically, elements in a sequence have an index.

beloglazov commented 11 years ago

I see, thanks for a quick reply :)

AndreaCensi commented 11 years ago

No problem! have a good day.