Make functions callable without having to type parentheses. Usage: %autocall [mode] The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the value is toggled on and off (remembering the previous state). In more detail, these values mean:
(self, parameter_s='')
| 62 | @skip_doctest |
| 63 | @line_magic |
| 64 | def autocall(self, parameter_s=''): |
| 65 | """Make functions callable without having to type parentheses. |
| 66 | |
| 67 | Usage: |
| 68 | |
| 69 | %autocall [mode] |
| 70 | |
| 71 | The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the |
| 72 | value is toggled on and off (remembering the previous state). |
| 73 | |
| 74 | In more detail, these values mean: |
| 75 | |
| 76 | 0 -> fully disabled |
| 77 | |
| 78 | 1 -> active, but do not apply if there are no arguments on the line. |
| 79 | |
| 80 | In this mode, you get:: |
| 81 | |
| 82 | In [1]: callable |
| 83 | Out[1]: <built-in function callable> |
| 84 | |
| 85 | In [2]: callable 'hello' |
| 86 | ------> callable('hello') |
| 87 | Out[2]: False |
| 88 | |
| 89 | 2 -> Active always. Even if no arguments are present, the callable |
| 90 | object is called:: |
| 91 | |
| 92 | In [2]: float |
| 93 | ------> float() |
| 94 | Out[2]: 0.0 |
| 95 | |
| 96 | Note that even with autocall off, you can still use '/' at the start of |
| 97 | a line to treat the first argument on the command line as a function |
| 98 | and add parentheses to it:: |
| 99 | |
| 100 | In [8]: /str 43 |
| 101 | ------> str(43) |
| 102 | Out[8]: '43' |
| 103 | |
| 104 | # all-random (note for auto-testing) |
| 105 | """ |
| 106 | |
| 107 | if parameter_s: |
| 108 | arg = int(parameter_s) |
| 109 | else: |
| 110 | arg = 'toggle' |
| 111 | |
| 112 | if not arg in (0, 1, 2, 'toggle'): |
| 113 | error('Valid modes: (0->Off, 1->Smart, 2->Full') |
| 114 | return |
| 115 | |
| 116 | if arg in (0, 1, 2): |
| 117 | self.shell.autocall = arg |
| 118 | else: # toggle |
| 119 | if self.shell.autocall: |
| 120 | self._magic_state.autocall_save = self.shell.autocall |
| 121 | self.shell.autocall = 0 |
nothing calls this directly
no outgoing calls
no test coverage detected