MCPcopy Index your code
hub / github.com/ipython/ipython / get_tail

Method get_tail

IPython/core/history.py:850–906  ·  view source on GitHub ↗

Get the last n lines from the history database. Most recent entry last. Completion will be reordered so that that the last ones are when possible from current session. Parameters ---------- n : int The number of lines to get raw,

(
        self,
        n: int = 10,
        raw: bool = True,
        output: bool = False,
        include_latest: bool = False,
    )

Source from the content-addressed store, hash-verified

848
849 @catch_corrupt_db
850 def get_tail(
851 self,
852 n: int = 10,
853 raw: bool = True,
854 output: bool = False,
855 include_latest: bool = False,
856 ) -> Iterable[tuple[int, int, InOrInOut]]:
857 """Get the last n lines from the history database.
858
859 Most recent entry last.
860
861 Completion will be reordered so that that the last ones are when
862 possible from current session.
863
864 Parameters
865 ----------
866 n : int
867 The number of lines to get
868 raw, output : bool
869 See :meth:`get_range`
870 include_latest : bool
871 If False (default), n+1 lines are fetched, and the latest one
872 is discarded. This is intended to be used where the function
873 is called by a user command, which it should not return.
874
875 Returns
876 -------
877 Tuples as :meth:`get_range`
878 """
879 self.writeout_cache()
880 if not include_latest:
881 n += 1
882 # cursor/line/entry
883 this_cur = list(
884 self._run_sql(
885 "WHERE session == ? ORDER BY line DESC LIMIT ? ",
886 (self.session_number, n),
887 raw=raw,
888 output=output,
889 )
890 )
891 other_cur = list(
892 self._run_sql(
893 "WHERE session != ? ORDER BY session DESC, line DESC LIMIT ?",
894 (self.session_number, n),
895 raw=raw,
896 output=output,
897 )
898 )
899
900 everything: list[tuple[int, int, InOrInOut]] = this_cur + other_cur
901
902 everything = everything[:n]
903
904 if not include_latest:
905 return list(everything)[:0:-1]
906 return list(everything)[::-1]
907

Callers 7

load_history_stringsMethod · 0.45
historyMethod · 0.45
rerunMethod · 0.45
test_historyFunction · 0.45

Calls 2

writeout_cacheMethod · 0.95
_run_sqlMethod · 0.80