Repository: ipython/ipython

Issue:
"?" and expressions
[tried with ipython 0.13.2, 1.0.0 and 1.1.0]

Requesting information for a object returned by an expression (in the example below the object is stored in a `list`, and the expression is extracting an element from the list).

Is this intended ? (When using only `?` in ipython, the documentation printed suggests that it should be working - the example given `{}.get?` is also not working).

```
In [1]: ?['a','b'][0]
Object `` not found.
```

The following is working though:

```
In [2]: o = ['a','b'][0]

In [3]: ?o
Type:       str
String Form:a
Length:     1
Docstring:
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
```



Discussion:
pinfo (what `?` is short for) doesn't evaluate the line, so you don't get any information about the results of expressions, because they don't exist. Since the evaluation of the expression can be arbitrarily expensive, we don't want to be executing code that the user hasn't actually requested to execute.

We have the same behavior in completion, where there is an option (greedy) to allow evaluation of expressions prior to completion. This is off by default, but it is an option. Perhaps we could add a similar (off by default) option to pinfo.

`?` also allows you to examine a name in an incomplete statement (e.g. `a = [foo?` should give info on `foo`). Working out which bit to evaluate in such a situation would be tricky.

Calling `?` in ipython brings up a documentation page that I understand to be a different story, and even give the example `{}.get?` to demonstrate it (and that example is not working).

Rats, yes, we don't keep that document as up-to-date as it should be. I
guess we don't tend to refer to it much.

On 23 September 2013 14:45, Laurent Gautier notifications@github.comwrote:

> Calling ? in ipython brings up a documentation page that I understand to
> be a different story, and even give the example {}.get? to demonstrate it
> (and that example is not working).
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/4249#issuecomment-24957757
> .

Tsk, tsk, tsk...

I'd like to see things the other way around: the documentation is clearly stating what the code should do. ;-)

Well, in principle, it is. But then we change our mind about what the code
should do, and there's a lot of docs in different places (Sphinx docs, wiki
pages, docstrings, interactive help things), and we don't remember to
update them all.

On 23 September 2013 16:08, Laurent Gautier notifications@github.comwrote:

> Tsk, tsk, tsk...
> 
> I'd like to see things the other way around: the documentation is clearly
> stating what the code should do. ;-)
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/4249#issuecomment-24962893
> .


Resolving patch:
diff --git a/IPython/core/usage.py b/IPython/core/usage.py
--- a/IPython/core/usage.py
+++ b/IPython/core/usage.py
@@ -103,11 +103,6 @@
   If you just want to see an object's docstring, type '%pdoc object' (without
   quotes, and without % if you have automagic on).
 
-  Both %pdoc and ?/?? give you access to documentation even on things which are
-  not explicitely defined. Try for example typing {}.get? or after import os,
-  type os.path.abspath??. The magic functions %pdef, %source and %file operate
-  similarly.
-
 * Completion in the local namespace, by typing TAB at the prompt.
 
   At any time, hitting tab will complete any available python commands or


Test patch: