Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/core/tips.py: 53%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

15 statements  

1from datetime import datetime 

2import os 

3from random import choice 

4from typing import Any 

5 

6_tips: Any = { 

7 # (month, day) 

8 "every_year": { 

9 (1, 1): "Happy new year!", 

10 # European time: 

11 # [2/8/25, 23:28:24] Fernando Perez: Hi! Yes, this was my first public 

12 # announcement: 

13 # [2/8/25, 23:28:25] Fernando Perez: 

14 # https://mail.python.org/pipermail/python-list/2001-December/093408.html 

15 # [2/8/25, 23:28:55] Fernando Perez: All that started two months earlier 

16 # - in October 2001 I read this article: 

17 # [2/8/25, 23:28:55] Fernando Perez: 

18 # https://web.archive.org/web/20011202000624/http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html 

19 # [2/8/25, 23:29:05] Fernando Perez: Which is also archived here: 

20 # [2/8/25, 23:29:05] Fernando Perez: 

21 # https://docstore.mik.ua/orelly/weblinux2/orn/interactive_python.html 

22 # [2/8/25, 23:29:48] Fernando Perez: That article put me on the trail of 

23 # LazyPython, and I also found out (can’t remember where) about IPP 

24 # (Interactive Python Prompt), another similar projecd by Janko Hauser. 

25 # [2/8/25, 23:30:20] Fernando Perez: A also read an article around that 

26 # time, about new features in Python 2.0, which spoke of how 

27 # sys.displayhook could be programmed to call any object you wanted. 

28 # [2/8/25, 23:31:01] Fernando Perez: Those things together gave me the 

29 # idea of implementing a stateful object, the “IPython Prompt”, that 

30 # could store a cache of old results, Mathematica-style, and that could 

31 # have all kinds of other useful tricks up its sleeve. 

32 # [2/8/25, 23:31:17] Fernando Perez: I can’t remember if I did the 

33 # prompt stuff first and then read about LazyPython/IPP. 

34 # [2/8/25, 23:31:41] Fernando Perez: I do know that, implementation 

35 # wise, at first I just did the tiny IPython 0.0.1 that I posted much 

36 # later on github as a gist: 

37 # [2/8/25, 23:31:55] Fernando Perez: 

38 # https://gist.github.com/fperez/1579699 

39 # [2/8/25, 23:32:03] Fernando Perez: But I only shared that publicly 

40 # much later. 

41 # [2/8/25, 23:33:19] Fernando Perez: I did find out about IPP/LazyPython 

42 # sometime in October, contacted Janko and Nathan who told me to use 

43 # their code at will but said they were busy with other things, and got 

44 # cranking for a few mad weeks on what became the IPython 0.2.0 that I 

45 # posted about in that comp.lang.python thread of December 2001. 

46 # [2/8/25, 23:33:52] Fernando Perez: That period from Oct 11 to Dec 9 

47 # 2001 was maniacal coding, with very little sleep 🙂 

48 ( 

49 10, 

50 11, 

51 ): "IPython's first line of code was written {} years ago by Fernando Pérez".format( 

52 datetime.now().year - 2001 

53 ), 

54 ( 

55 12, 

56 9, 

57 ): "IPython 0.0.2 was announced {} years ago: https://mail.python.org/pipermail/python-list/2001-December/093408.html".format( 

58 datetime.now().year - 2001 

59 ), 

60 ( 

61 3, 

62 8, 

63 ): "Today is International Women's Day: https://www.internationalwomensday.com/", 

64 ( 

65 3, 

66 31, 

67 ): "Happy International Transgender Day of Visibility! You are valid. You matter. https://en.wikipedia.org/wiki/International_Transgender_Day_of_Visibility", 

68 }, 

69 "random": [ 

70 "Use `F2` or %edit with no arguments to open an empty editor with a temporary file.", 

71 "Run your doctests from within IPython for development and debugging. The special %doctest_mode command toggles a mode where the prompt, output and exceptions display matches as closely as possible that of the default Python interpreter.", 

72 "You can use `files = !ls *.png`", 

73 "Use the IPython.lib.demo.Demo class to load any Python script as an interactive demo.", 

74 "Put a ';' at the end of a line to suppress the printing of output.", 

75 "You can use Ctrl-O to force a new line in terminal IPython", 

76 "Use `object?` to see the help on `object`, `object??` to view its source", 

77 "`?` alone on a line will brings up IPython's help", 

78 "You can use `%hist` to view history, see the options with `%history?`", 

79 "You can change the editing mode of IPython to behave more like vi, or emacs.", 

80 "IPython 9.0+ has hooks to integrate AI/LLM completions.", 

81 "Use `%timeit` or `%%timeit`, and the `-r`, `-n`, and `-o` options to easily profile your code.", 

82 "Use `ipython --help-all | less` to view all the IPython configuration options.", 

83 "Use `--theme`, or the `%colors` magic to change IPython's themes and colors.", 

84 "The `%timeit` magic has a `-o` flag, which returns the results, making it easy to plot. See `%timeit?`.", 

85 ], 

86} 

87 

88if os.name == "nt": 

89 _tips["random"].extend( 

90 [ 

91 "We can't show you all tips on Windows as sometimes Unicode characters crash the Windows console, please help us debug it." 

92 ] 

93 ) 

94 # unicode may crash windows console, so we filter out tips with non-ASCII characters. 

95 _tips["every_year"] = { 

96 k: v 

97 for k, v in _tips["every_year"].items() 

98 if all(ord(char) < 128 for char in v) 

99 } 

100else: 

101 _tips["random"].extend( 

102 [ 

103 "You can use LaTeX or Unicode completion, `\\alpha<tab>` will insert the α symbol.", 

104 "You can find how to type a LaTeX symbol by back-completing it, eg `\\θ<tab>` will expand to `\\theta`.", 

105 "You can find how to type a Unicode symbol by back-completing it, eg `\\Ⅷ<tab>` will expand to `\\ROMAN NUMERAL EIGHT`.", 

106 "IPython supports combining unicode identifiers, eg F\\vec<tab> will become F⃗, useful for physics equations. Play with \\dot \\ddot and others.", 

107 ] 

108 ) 

109 

110 

111def pick_tip() -> str: 

112 current_date = datetime.now() 

113 month, day = current_date.month, current_date.day 

114 

115 if (month, day) in _tips["every_year"]: 

116 return _tips["every_year"][(month, day)] 

117 

118 return choice(_tips["random"])