@@ -144,6 +144,29 @@ def __str__(self) -> str:
144144 # complex period
145145 return '{}:{}-{:02d}:{}' .format (unit , year , month , size )
146146
147+ def __contains__ (self , other : object ) -> bool :
148+ """Checks if a ``period`` contains another one.
149+
150+ Args:
151+ other (object): The other ``Period``.
152+
153+ Returns:
154+ True if ``other`` is contained, otherwise False.
155+
156+ Example:
157+ >>> period = Period((YEAR, Instant((2021, 1, 1)), 1))
158+ >>> sub_period = Period((MONTH, Instant((2021, 1, 1)), 3))
159+
160+ >>> sub_period in period
161+ True
162+
163+ """
164+
165+ if isinstance (other , types .Period ):
166+ return self .start <= other .start and self .stop >= other .stop
167+
168+ return super ().__contains__ (other )
169+
147170 @property
148171 def date (self ) -> datetime .date :
149172 """The date representation of the ``period``'s' start date.
@@ -512,23 +535,3 @@ def offset(
512535 """
513536
514537 return self .__class__ ((self [0 ], self [1 ].offset (offset , self [0 ] if unit is None else unit ), self [2 ]))
515-
516- def contains (self , other : types .Period ) -> bool :
517- """Checks if a ``period`` contains another one.
518-
519- Args:
520- other (:obj:`.Period`): The other ``Period``.
521-
522- Returns:
523- True if ``other`` is contained, otherwise False.
524-
525- Example:
526- >>> period = Period((YEAR, Instant((2021, 1, 1)), 1))
527- >>> sub_period = Period((MONTH, Instant((2021, 1, 1)), 3))
528-
529- >>> period.contains(sub_period)
530- True
531-
532- """
533-
534- return self .start <= other .start and self .stop >= other .stop
0 commit comments