Skip to content

Commit

Permalink
add from_counter convenience classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed Mar 20, 2022
1 parent ce29abf commit f62a24b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nbsafety/data_model/code_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,16 @@ def all_cells_most_recently_run_for_each_id(
) -> Generator["ExecutedCodeCell", None, None]:
yield from cls._current_cell_by_cell_id.values()

@classmethod
def from_counter(cls, ctr: int) -> "ExecutedCodeCell":
return cls._cell_by_cell_ctr[ctr]

@classmethod
def from_timestamp(cls, ts: TimestampOrCounter) -> "ExecutedCodeCell":
if isinstance(ts, Timestamp):
return cls._cell_by_cell_ctr[ts.cell_num]
return cls.from_counter(ts.cell_num)
else:
return cls._cell_by_cell_ctr[ts]
return cls.from_counter(ts)

@classmethod
def from_id(cls, cell_id: CellId) -> Optional["ExecutedCodeCell"]:
Expand Down

0 comments on commit f62a24b

Please sign in to comment.