Skip to content

Commit

Permalink
More typing cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
iluvcapra committed Jun 1, 2023
1 parent 179808f commit a6f042c
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions pycmx/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# (c) 2023 Jamie Hardt

from .parse_cmx_statements import (StmtEvent, StmtClipName, StmtSourceFile, StmtAudioExt, StmtUnrecognized, StmtEffectsName)
from .edit import Edit
from .edit import Edit

from typing import List, Generator
from typing import List, Generator, Optional, Tuple, Any

class Event:
"""
Expand Down Expand Up @@ -32,17 +32,19 @@ def edits(self) -> List[Edit]:
clip_names = self._clip_name_statements()
source_files= self._source_file_statements()

the_zip = [edits_audio]
the_zip: List[List[Any]] = [edits_audio]

if len(edits_audio) == 2:
cn = [None, None]
start_name: Optional[StmtClipName] = None
end_name: Optional[StmtClipName] = None

for clip_name in clip_names:
if clip_name.affect == 'from':
cn[0] = clip_name
start_name = clip_name
elif clip_name.affect == 'to':
cn[1] = clip_name
end_name = clip_name

the_zip.append(cn)
the_zip.append([start_name, end_name])
else:
if len(edits_audio) == len(clip_names):
the_zip.append(clip_names)
Expand All @@ -59,13 +61,17 @@ def edits(self) -> List[Edit]:
# attach trans name to last event
try:
trans_statement = self._trans_name_statements()[0]
trans_names = [None] * (len(edits_audio) - 1)
trans_names: List[Optional[Any]] = [None] * (len(edits_audio) - 1)
trans_names.append(trans_statement)
the_zip.append(trans_names)
except IndexError:
the_zip.append([None] * len(edits_audio) )

return [ Edit(e1[0],e1[1],n1,s1,u1) for (e1,n1,s1,u1) in zip(*the_zip) ]
return [ Edit(edit_statement=e1[0],
audio_ext_statement=e1[1],
clip_name_statement=n1,
source_file_statement=s1,
trans_name_statement=u1) for (e1,n1,s1,u1) in zip(*the_zip) ]

@property
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
Expand All @@ -76,19 +82,19 @@ def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
if type(s) is StmtUnrecognized:
yield s

def _trans_name_statements(self):
def _trans_name_statements(self) -> List[StmtEffectsName]:
return [s for s in self.statements if type(s) is StmtEffectsName]

def _edit_statements(self):
def _edit_statements(self) -> List[StmtEvent]:
return [s for s in self.statements if type(s) is StmtEvent]

def _clip_name_statements(self):
def _clip_name_statements(self) -> List[StmtClipName]:
return [s for s in self.statements if type(s) is StmtClipName]

def _source_file_statements(self):
def _source_file_statements(self) -> List[StmtSourceFile]:
return [s for s in self.statements if type(s) is StmtSourceFile]

def _statements_with_audio_ext(self):
def _statements_with_audio_ext(self) -> Generator[Tuple[StmtEvent, Optional[StmtAudioExt]], None, None]:
for (s1, s2) in zip(self.statements, self.statements[1:]):
if type(s1) is StmtEvent and type(s2) is StmtAudioExt:
yield (s1,s2)
Expand Down

0 comments on commit a6f042c

Please sign in to comment.