Hello, thank you for your feedback!
I could think of a trick that inspect.getsource() might use if the class contains at least one method: it could look at a method and try its `__code__.co_filename` attribute (maybe only if the `__file__` attribute for the module found via the class's `__module__` doesn't exist -- I'm sure Jupyter can arrange for that to be the case). But I see how that would be a problem (I can think of plenty of reasons why a class might not have any methods).
That is a great idea, in addition getsource would have to filter out inherited methods (which should be doable, but indeed exclude classes). Would you prefer such a patch to inspect.getsource over the adding __filename__?
I do think that your proposal is reasonable, although I wonder what the Jupyter developers think of it. (How closely are you connected to that project?)
I am not affiliated with Jupyter at all and I imagine that I'd be prone to asking "would it be nice if inspect.getsource worked better?", which likely doesn't yield the most interesting answers.
We can chase the related reports: https://github.com/jupyter/notebook/issues/3802 https://github.com/ipython/ipython/issues/11249 The topic does seem to pop up now and then: https://stackoverflow.com/questions/51566497/getting-the-source-of-an-object-defined-in-a-jupyter-notebook https://stackoverflow.com/questions/35854373/python-get-source-code-of-class-using-inspect Best regards Thomas _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/UL376F3Y6FKJUZ2HZDA3ERFUDDOX67X4/ Code of Conduct: http://python.org/psf/codeofconduct/