?magic does not show variable definitions, only class definitions
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 4.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 6
Description
Best illustrated with a short example:
```
$ ipython
Python 3.9.9 (main, Nov 16 2021, 03:08:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.30.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: newvar = 4.64 # special variable units foo etcetc
In [2]: newvar??
Type: float
String form: 4.64
Docstring: Convert a string or number to a floating point number, if possible.
In [3]: def foo():
...: return 4.64 # have to abuse def to be able to find this help later
...:
In [4]: foo??
Signature: foo()
Docstring:
Source:
def foo():
return 4.64 # have to abuse def to be able to find this help later
File: ~/
Type: function
In [5]:
```
Problem is that `newvar??` should have shown me the source line where newvar was defined, including my comment, not just given me useless help for the float base class.
It's nice that `??` works properly for functions, but it's not nice that it does not work consistently for variables. If I wanted help for the class of a variable, why not do `newvar__class__??` ? I can do `dir(newvar)` to explore that stuff.
Many is the time that one needs to be able to ask ipython what some variable is, and at least be able to find where it was defined. Unfortunately because not all code is clean, neat and small.
`??` as applied to functions is nice, it makes end-of-line comments useful.
If this worked right for variables, then it would help encourage people to comment a new variable on the same line, which would greatly help figuring out why they named it what they did.
I'd be happy for them to just use a variable name that is the acronym of the phrase that describes the variable, such a phrase preferably written in full on the same defining line in such a comment. If anyone wants to know what such an acronym means, they can then just ask with `??`.
Please fix.
Contributor guide
Assessment
This issue has not been assessed yet.