Closed WangGithubUser closed 1 year ago
The correct way to do this is:
from objprint import op
def _f():
pass
op(_f.__code__, honor_existing=False)
Whether the user wants the original format or the objprint
format is arbitrary, what we should do is to keep consistency - always honor the existing format if there is one. If the user want it otherwise, they need to explicitly do it.
Even if we want to print the code object with objprint
format by default (which we do NOT), the implementation is not ideal. We can't just add the logic to an already complicated logic chain - it's an exemption. What if we want to add more exemptions in the future? Having the exemption with the generic logic is generally not a good idea.
As for the feature request - I stand my point, which is the user needs to pass in honor_existing
to trigger this behavior, we should no represent them.
@gaogaotiantian Thanks for responding!I learned a lot.I will now close this issue and the PR.
Reprodution
Run the script below:
It will give a output like this:
<code object _f at 0x00000222E40EF100, file "C:\Users\user\AppData\Roaming\JetBrains\PyCharmCE2023.2\scratches\scratch.py", line 2>
Excepted behavior
objprint
should show all the attributes in the code object.