Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDecan committed Mar 9, 2020
1 parent 2513632 commit fb473a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Development

### Fixed

- Fix invalid representations of non-atomic intervals composed of a singleton ([#22](https://github.com/AlexandreDecan/portion/issues/22)).


## 2.0.0 (2020-03-06)

### Added
Expand Down
29 changes: 16 additions & 13 deletions portion/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,20 @@ def __hash__(self):
return hash(tuple([self.lower, self.upper]))

def __repr__(self):
if self.empty:
return '()'
elif self.lower == self.upper:
return '[{}]'.format(repr(self.lower))
else:
return ' | '.join(
'{}{},{}{}'.format(
'[' if i.left == Bound.CLOSED else '(',
repr(i.lower),
repr(i.upper),
']' if i.right == Bound.CLOSED else ')',
intervals = []

for interval in self:
if interval.empty:
intervals.append('()')
elif interval.lower == interval.upper:
intervals.append('[{}]'.format(repr(interval.lower)))
else:
intervals.append(
'{}{},{}{}'.format(
'[' if interval.left == Bound.CLOSED else '(',
repr(interval.lower),
repr(interval.upper),
']' if interval.right == Bound.CLOSED else ')',
)
)
for i in self._intervals
)
return ' | '.join(intervals)

0 comments on commit fb473a4

Please sign in to comment.