gjhiggins/rdflib — Issue #118: Support Python's set operations on Graph
Author: gjhiggins
Created: 2011-10-19 01:26:02+00:00
State: open

Originally filed by lindstr...@gmail.com on 2010-02-12T11:10:28

The Graph class already has great support for set algebra. But the operations differ from
those defined for the builtin set type in Python. Python's set has: "|", "&" and "^". "-" works
the same on set and Graph today.

We could easily add support by just adding e.g.::

__or__ = __add__
__and__ = __mul__
__xor__ = lambda self, other: (self - other) + (other - self)

But perhaps the older forms should be deprecated as well? (I.e. call
warnings.warn(DeprecationWarning) and then call the new set-based ones.)

There are actually some more things if we want to go for full API compliance:

- ">", "<", ">=", "<="
- "__i*__"-versions
- named versions of the operator overloads.

See .