-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Labels
26.04An item we hope to do in the 26.04 cycleAn item we hope to do in the 26.04 cyclerainy daySmall items done in ~10% of each week's timeSmall items done in ~10% of each week's timetestsRelated to tests or testingRelated to tests or testing
Description
ops.testing.State.get_relation(relation: int) is typed as returning an ops.testing.RelationBase, because it could return any of Relation, PeerRelation, and SubordinateRelation.
When type checking tests, code like this is often needed:
retrieved_relation = state.get_relation(relation.id)
assert isinstance(retrieved_relation, Relation)
Which isn't terrible, but as @dimaqq noted, could be better:
Aside: I wish this was more ergonomic for our users.
Like if they could conceptually write:
rel = state.get_relation<Relation>(rel.id) # or rel = state.get_relation(rel.id, kind=Relation) # runtime error on mismatchPerhaps more Pythonically:
rel = state.get_regular_relation(rid) per = state.get_peer_relation(pid) sub = state.get_subordinate_relation(sid)
Metadata
Metadata
Assignees
Labels
26.04An item we hope to do in the 26.04 cycleAn item we hope to do in the 26.04 cyclerainy daySmall items done in ~10% of each week's timeSmall items done in ~10% of each week's timetestsRelated to tests or testingRelated to tests or testing