This is really hard to follow.

```python
        if (self == target and
                ((pos == 'left') or
                 (pos in ('right', 'last-sibling') and
                  target == target.get_last_sibling()) or
                 (pos == 'first-sibling' and
                  target == target.get_first_sibling()))):
            return
```

Or more explicit:

```python
        if self == target:
            if pos == 'left':
                return
            if (pos in ('right', 'last-sibling') and
                    target == target.get_last_sibling()):
                return
            if (pos == 'first-sibling' and
                    target == target.get_first_sibling()):
                return
```