33"""
44from __future__ import annotations
55
6- import collections .abc
76import dataclasses
87import decimal
98import fnmatch
1312import re
1413import sys
1514import typing
15+ from typing import overload
1616from glob import iglob
1717
1818from . import constants , utils
@@ -144,7 +144,7 @@ def __init__(self,
144144 # Round subframes to match sequence
145145 if self ._frameSet is not None and self ._frameSet .hasSubFrames ():
146146 self ._frameSet = FrameSet ([
147- utils .quantize (frame , self ._decimal_places )
147+ utils .quantize (frame , self ._decimal_places ) # type: ignore[arg-type]
148148 for frame in self ._frameSet
149149 ])
150150
@@ -436,7 +436,7 @@ def setFrameSet(self, frameSet: FrameSet|None) -> None:
436436 if frameSet is not None and frameSet .hasSubFrames ():
437437 if all (isinstance (frame , decimal .Decimal ) for frame in frameSet ):
438438 frameSet = FrameSet ([
439- utils .quantize (frame , self ._decimal_places )
439+ utils .quantize (frame , self ._decimal_places ) # type: ignore[arg-type]
440440 for frame in frameSet
441441 ])
442442 self ._frameSet = frameSet
@@ -519,25 +519,25 @@ def invertedFrameRange(self) -> str:
519519 return ''
520520 return self ._frameSet .invertedFrameRange (self ._zfill )
521521
522- def start (self ) -> int :
522+ def start (self ) -> int | float | decimal . Decimal :
523523 """
524524 Returns the start frame of the sequence's :class:`.FrameSet`.
525525 Will return 0 if the sequence has no frame pattern.
526526
527527 Returns:
528- int:
528+ int | float | decimal.Decimal :
529529 """
530530 if not self ._frameSet :
531531 return 0
532532 return self ._frameSet .start ()
533533
534- def end (self ) -> int :
534+ def end (self ) -> int | float | decimal . Decimal :
535535 """
536536 Returns the end frame of the sequences :class:`.FrameSet`.
537537 Will return 0 if the sequence has no frame pattern.
538538
539539 Returns:
540- int:
540+ int | float | decimal.Decimal :
541541 """
542542 if not self ._frameSet :
543543 return 0
@@ -611,9 +611,17 @@ def index(self, idx: int) -> str:
611611 Returns:
612612 str:
613613 """
614- return self .__getitem__ (idx ) # type: ignore
614+ return self .__getitem__ (idx )
615+
616+ @overload
617+ def batches (self , batch_size : int , paths : typing .Literal [True ]) -> typing .Iterator [utils ._islice [str ]]:
618+ ...
615619
616- def batches (self , batch_size : int , paths : bool = False ) -> typing .Iterable [str | FileSequence ]:
620+ @overload
621+ def batches (self , batch_size : int , paths : typing .Literal [False ] = ...) -> typing .Iterator [FileSequence ]:
622+ ...
623+
624+ def batches (self , batch_size : int , paths : bool = False ) -> typing .Iterator [utils ._islice [str ]] | typing .Iterator [FileSequence ]:
617625 """
618626 Returns a generator that yields groups of file paths, up to ``batch_size``.
619627 Convenience method for ``fileseq.utils.batchIterable(self, batch_size)``
@@ -629,7 +637,7 @@ def batches(self, batch_size: int, paths: bool = False) -> typing.Iterable[str |
629637 generator: yields batches of file paths or FileSequence subranges of sequence
630638 """
631639 if len (self ) == 0 :
632- return []
640+ return iter ([])
633641
634642 if paths :
635643 # They just want batches of the individual file paths
@@ -692,7 +700,7 @@ def from_dict(cls, state: dict[str, typing.Any]) -> FileSequence:
692700 fs .__setstate__ (state )
693701 return fs
694702
695- def __iter__ (self ) -> collections . abc . Generator [str , None , None ]:
703+ def __iter__ (self ) -> typing . Iterator [str ]:
696704 """
697705 Allow iteration over the path or paths this :class:`FileSequence`
698706 represents.
@@ -709,7 +717,15 @@ def __iter__(self) -> collections.abc.Generator[str, None, None]:
709717 for f in self ._frameSet :
710718 yield self .frame (f )
711719
712- def __getitem__ (self , idx : typing .Any ) -> str | FileSequence :
720+ @typing .overload
721+ def __getitem__ (self , idx : slice ) -> FileSequence :
722+ pass
723+
724+ @typing .overload
725+ def __getitem__ (self , idx : int ) -> str :
726+ pass
727+
728+ def __getitem__ (self , idx : typing .Any ) -> str | FileSequence :
713729 """
714730 Allows indexing and slicing into the underlying :class:`.FrameSet`
715731
@@ -815,7 +831,7 @@ def __components(self) -> _Components:
815831 def yield_sequences_in_list (
816832 cls ,
817833 paths : typing .Iterable [str ],
818- using : FileSequence | None = None ,
834+ using : ' FileSequence | None' = None ,
819835 pad_style : constants ._PadStyle = PAD_STYLE_DEFAULT ,
820836 allow_subframes : bool = False ) -> typing .Iterator [FileSequence ]:
821837 """
@@ -895,7 +911,7 @@ def yield_sequences_in_list(
895911 seqs [key ].add (frame )
896912
897913 def start_new_seq () -> FileSequence :
898- seq = cls .__new__ (cls )
914+ seq : FileSequence = cls .__new__ (cls )
899915 seq ._dir = dirname or ''
900916 seq ._base = basename or ''
901917 seq ._ext = ext or ''
@@ -1329,7 +1345,7 @@ def __call__(self,
13291345 zfill : int | None ,
13301346 decimal_places : typing .Optional [int ] = 0 ,
13311347 get_frame : typing .Optional [typing .Callable [[str ], str ]] = None
1332- ) -> collections . abc . Generator [str , None , None ]:
1348+ ) -> typing . Iterator [str ]:
13331349 """
13341350 Yield only path elements from iterable which have a frame padding that
13351351 matches the given target padding numbers. If zfill is None only the
@@ -1424,9 +1440,14 @@ def set_has_padded() -> None:
14241440 continue
14251441
14261442 @classmethod
1427- def _filterByPaddingNum (cls , * args , ** kwargs ) -> typing .Generator [str ]: # type: ignore
1443+ def _filterByPaddingNum (cls ,
1444+ iterable : typing .Iterable [str ],
1445+ zfill : int | None ,
1446+ decimal_places : typing .Optional [int ] = 0 ,
1447+ get_frame : typing .Optional [typing .Callable [[str ], str ]] = None
1448+ ) -> typing .Iterator [str ]:
14281449 ctx = cls ._FilterByPaddingNum ()
1429- return ctx (* args , ** kwargs )
1450+ return ctx (iterable , zfill , decimal_places , get_frame )
14301451
14311452 @classmethod
14321453 def getPaddingChars (cls , num : int , pad_style : constants ._PadStyle = PAD_STYLE_DEFAULT ) -> str :
0 commit comments