The spacing makes this hard to read. I'd format this more like:
```python
if (original_location.tag == ref.tag and 
        original_location.org == ref.org and
        original_location.course == ref.course):
    new_ref = ref.replace(
        tag=target_location_namespace.tag,
        org=target_location_namespace.org,
        course=target_location_namespace.course
    ).url()
```
or
```python
def locations_equal(a, b):
    return (a.tag == b.tag and a.org == b.org and a.course == b.course)

if locations_equal(original_location, ref):
    new_ref = ref.replace(
        tag=target_location_namespace.tag,
        org=target_location_namespace.org,
        course=target_location_namespace.course
    ).url()
```