02.12.13 17:55, Gregory Salvan написав(ла):class FooReader:
Hi,
I've made a try of a function that check object/class members for duck
typing.
For now I've basically called it isducktype(X, A)
it returns true if:
- X has all attributes of A
- X methods have same number of arguments than corresponding A methods
or if A.__ducktypecheck__(X) returns True
Behaviour looks like isinstance and issubclass (support tuples...).
def read(self, n=None): ...
class BarReader:
def read(self, amount=-1): ...
class BazReader:
def read(self, size=-1, chars=-1, firstline=False): ...
Instances of all three classes can be used where needed an object with the read() method which are called with one positional argument or without arguments. Is it possible to use isducktype() for such case?
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas