Skip to content

Commit 8d07020

Browse files
1.5.0
1 parent 24fc0c3 commit 8d07020

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ Distributed under [LGPLv3 - GNU Lesser General Public License, version 3](https:
365365
This library adheres to a [semantic versioning](https://semver.org) scheme.
366366

367367

368+
**1.5.0** (2018-04-17)
369+
370+
- `Interval.__init__` accepts `Interval` instances in addition to `AtomicInterval` ones.
371+
372+
368373
**1.4.0** (2018-04-17)
369374

370375
- Function `I.to_string` to export an interval to a string, with many options to customize the representation.

intervals.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33
__package__ = 'python-intervals'
4-
__version__ = '1.4.0'
4+
__version__ = '1.5.0'
55
__licence__ = 'LGPL3'
66
__author__ = 'Alexandre Decan'
77
__url__ = 'https://github.com/AlexandreDecan/python-intervals'
@@ -488,7 +488,7 @@ class Interval:
488488
This class represents an interval.
489489
490490
An interval is an (automatically simplified) union of atomic intervals.
491-
It can be created either by passing atomic intervals, or by using one of the helpers
491+
It can be created either by passing (atomic) intervals, or by using one of the helpers
492492
provided in this module (open(..), closed(..), etc).
493493
494494
Unless explicitly specified, all operations on an Interval instance return Interval instances.
@@ -498,15 +498,20 @@ class Interval:
498498

499499
def __init__(self, *intervals):
500500
"""
501-
Create an interval from a list of atomic intervals.
501+
Create an interval from a list of (atomic or not) intervals.
502502
503-
:param intervals: a list of atomic intervals.
503+
:param intervals: a list of (atomic or not) intervals.
504504
"""
505505
self._intervals = list()
506506

507507
for interval in intervals:
508-
if not interval.is_empty():
509-
self._intervals.append(interval)
508+
if isinstance(interval, Interval):
509+
self._intervals.extend(interval)
510+
elif isinstance(interval, AtomicInterval):
511+
if not interval.is_empty():
512+
self._intervals.append(interval)
513+
else:
514+
raise TypeError('Parameters must be Interval or AtomicInterval instances')
510515

511516
if len(self._intervals) == 0:
512517
# So we have at least one (empty) interval

test_intervals.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def test_creation():
4646
assert I.Interval() == I.open(0, 0)
4747
assert I.empty() == I.Interval()
4848

49+
assert I.Interval(I.closed(0, 1).to_atomic()) == I.closed(0, 1)
50+
assert I.Interval(I.closed(0, 1)) == I.closed(0, 1)
51+
assert I.Interval(I.closed(0, 1).to_atomic(), I.closed(2, 3)) == I.closed(0, 1) | I.closed(2, 3)
52+
assert I.Interval(I.closed(0, 1) | I.closed(2, 3)) == I.closed(0, 1) | I.closed(2, 3)
53+
54+
with pytest.raises(TypeError):
55+
I.Interval(1)
56+
4957

5058
def test_hash():
5159
assert hash(I.closed(0, 1).to_atomic()) is not None

0 commit comments

Comments
 (0)