@@ -324,9 +324,6 @@ def __init__(self,
324324 # restrictClass: type[M21ObjType] = base.Music21Object,
325325 super().__init__(**keywords)
326326
327- # TEMPORARY variable for v9 to deprecate the flat property. -- remove in v10
328- self._created_via_deprecated_flat = False
329-
330327 self.streamStatus = streamStatus.StreamStatus(self)
331328 self._unlinkedDuration = None
332329
@@ -451,13 +448,6 @@ def __iter__(self) -> iterator.StreamIterator[M21ObjType]:
451448 specialized :class:`music21.stream.StreamIterator` class, which
452449 adds necessary Stream-specific features.
453450 '''
454- # temporary for v9 -- remove in v10
455- if self._created_via_deprecated_flat:
456- warnings.warn('.flat is deprecated. Call .flatten() instead',
457- exceptions21.Music21DeprecationWarning,
458- stacklevel=3)
459- self._created_via_deprecated_flat = False
460-
461451 return t.cast(iterator.StreamIterator[M21ObjType],
462452 iterator.StreamIterator(self))
463453
@@ -4699,11 +4689,11 @@ def measure(self,
46994689 def template(self,
47004690 *,
47014691 fillWithRests=True,
4702- removeClasses= None,
4692+ removeClasses: Iterable[type|str]|set[type|str]|None = None,
47034693 retainVoices=True,
47044694 removeAll=False,
47054695 exemptFromRemove=frozenset(),
4706- ):
4696+ ) -> t.Self :
47074697 '''
47084698 Return a new Stream based on this one, but without the notes and other elements
47094699 but keeping instruments, clefs, keys, etc.
@@ -4874,14 +4864,11 @@ def template(self,
48744864
48754865 * Changed in v7: all arguments are keyword only.
48764866 * New in v9.9: added exemptFromRemove
4877- * Note: in v10
4867+ * Note: in v10: removeClasses cannot be boolean -- use removeAll instead
48784868 '''
48794869 out = self.cloneEmpty(derivationMethod='template')
48804870 if removeClasses is None:
48814871 removeClasses = {'GeneralNote', 'Dynamic', 'Expression'}
4882- elif removeClasses is True:
4883- removeClasses = set()
4884- removeAll = True
48854872 elif common.isIterable(removeClasses):
48864873 removeClasses = set(removeClasses)
48874874
@@ -4903,7 +4890,7 @@ def optionalAddRest():
49034890 elOffset = self.elementOffset(el, returnSpecial=True)
49044891
49054892 # retain all streams (exception: Voices if retainVoices is False
4906- if el.isStream and (retainVoices or ('Voice' not in el.classes)):
4893+ if isinstance(el, Stream) and (retainVoices or ('Voice' not in el.classes)):
49074894 optionalAddRest()
49084895 outEl = el.template(fillWithRests=fillWithRests,
49094896 removeClasses=removeClasses,
@@ -4919,7 +4906,7 @@ def optionalAddRest():
49194906
49204907 # okay now determine if we will be skipping or keeping this element
49214908 skip_element = False
4922- if removeAll is True :
4909+ if removeAll:
49234910 # with this setting we remove everything by default
49244911 skip_element = True
49254912 elif el.classSet.intersection(removeClasses):
@@ -7770,7 +7757,7 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType:
77707757 A very important method that returns a new Stream
77717758 that has all sub-containers "flattened" within it,
77727759 that is, it returns a new Stream where no elements nest within
7773- other elements.
7760+ other elements. (Prior to v7 this was the property .flat)
77747761
77757762 Here is a simple example of the usefulness of .flatten(). We
77767763 will create a Score with two Parts in it, each with two Notes:
@@ -7847,6 +7834,7 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType:
78477834
78487835 If `retainContainers=True` then a "semiFlat" version of the stream
78497836 is returned where Streams are also included in the output stream.
7837+ (Prior to v7 this was the property semiFlat)
78507838
78517839 In general, you will not need to use this because `.recurse()` is
78527840 more efficient and does not lead to problems of the same
@@ -7963,25 +7951,19 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType:
79637951 <music21.note.Note D>,
79647952 <music21.note.Note D>)
79657953
7966- OMIT_FROM_DOCS
7967-
7968- >>> r = stream.Stream()
7969- >>> for j in range(5):
7970- ... q = stream.Stream()
7971- ... for i in range(5):
7972- ... p = stream.Stream()
7973- ... p.repeatInsert(base.Music21Object(), [0, 1, 2, 3, 4])
7974- ... q.insert(i * 10, p)
7975- ... r.insert(j * 100, q)
7976-
7977- >>> len(r)
7978- 5
7979-
7980- >>> len(r.flatten())
7981- 125
7954+ .. note::Why did `.flat` become `.flatten()`? Early on music21's philosophy
7955+ was to use properties for commonly accessed "views" of a stream. This
7956+ worked well in the pre-IDE/debugger days of early Python 2. Now however
7957+ most of us program with IDEs and AI assistance that freely introspect the
7958+ attributes of objects. So if you're working with a Pitch object, your IDE
7959+ may have already looked up its .name or .accidental without your knowledge.
7960+ Properties are generally considered the same as attributes (that's what
7961+ they're designed for). The problem is that flattening a stream is a
7962+ time consuming algorithm that alters the stream and all its elements in
7963+ the process. Therefore streams should only be flattened when the programmer
7964+ requests them to be. The way to tell a modern IDE that a process may
7965+ have consequences is to make it a `.method()` not a `.property`.
79827966
7983- >>> r.flatten()[124].offset
7984- 444.0
79857967 '''
79867968 # environLocal.printDebug(['flatten(): self', self,
79877969 # 'self.activeSite', self.activeSite])
@@ -8046,20 +8028,6 @@ def flatten(self: StreamType, retainContainers=False) -> StreamType:
80468028
80478029 return sNew
80488030
8049- @property
8050- def flat(self):
8051- '''
8052- Deprecated: use `.flatten()` instead
8053-
8054- A property that returns the same flattened representation as `.flatten()`
8055- as of music21 v7.
8056-
8057- See :meth:`~music21.stream.base.Stream.flatten()` for documentation.
8058- '''
8059- flatStream = self.flatten(retainContainers=False)
8060- flatStream._created_via_deprecated_flat = True
8061- return flatStream
8062-
80638031 @overload
80648032 def recurse(self,
80658033 *,
0 commit comments