Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%pfile doesn't detect objects from the standard library #12960

Open
illright opened this issue May 10, 2021 · 3 comments
Open

%pfile doesn't detect objects from the standard library #12960

illright opened this issue May 10, 2021 · 3 comments
Labels

Comments

@illright
Copy link

Steps to reproduce

  • Execute import math
  • Execute %pfile math
  • Execute %pfile math.log

Expected result

Both calls to %pfile tell the user that math is a part of the standard library

Actual result

Both calls to %pfile produce an error:

No file found for math
No file found for math.log

System info

Manjaro Linux, Python 3.9.4, IPython 7.22.0 (reproduces on IPython 8.0.0.dev)

@MrMino
Copy link
Member

MrMino commented May 11, 2021

I don't think this would be the right result for pfile. You can run this on standard library without any problem, e.g. %pfile telnetlib. The issue pfile has with math is not that it is a standard library, but rather that it cannot find the python source code file the module points to, since it's a compiled binary. There's no source file - hence "No file found".

@illright
Copy link
Author

I think it could be helpful to point users towards the standard library in such cases, regardless of their setup.

Also, I don't really understand the mechanics of %pfile. I created a file test.py in the current directory with the contents specific_var = 5, then executed from test import specific_var and then %pfile specific_var. I expected it to point me towards file.py, but it also printed out No file found for specific_var.

@MrMino
Copy link
Member

MrMino commented May 13, 2021

I disagree. It would be very difficult to tell whether something is actually stdlib or not, you'd have to maintain a list throughout each platform × python version, which would be a nightmare'ish endeavour.

I expected it to point me towards file.py, but it also printed out No file found for specific_var.

As I understand it, you're giving it the value 5, which is not defined anywhere where %pfile can look. The docs say:

Print (or run through pager) the source code for an object.

5 is not defined in your file, and you cannot get its source code by using Python's introspection tools, hence No file found for specific_var.

@MrMino MrMino added the magics label Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants