You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to import prettyprinter/prettyprinter.py so that I could properly type-hint the 'context' argument to my custom printer function. However, when I did so, I was informed that prettyprinter.prettyprinter did not contain any attribute PrettyContext.
On investigation, I discovered that prettyprinter (the package corresponding to prettyprinter/) contains, on initial import, already contains a member named prettyprinter, but this member is actually just a circular reference to the package itself. This makes it impossible to import prettyprinter.prettyprinter (the module corresponding to prettyprinter/prettyprinter.py).
_prettyprinter=<module 'prettyprinter' from 'C:\\Python311\\Lib\\site-packages\\prettyprinter\\__init__.py'>
_prettyprinter.prettyprinter=<module 'prettyprinter' from 'C:\\Python311\\Lib\\site-packages\\prettyprinter\\__init__.py'>
_pp_pp=<module 'prettyprinter' from 'C:\\Python311\\Lib\\site-packages\\prettyprinter\\__init__.py'>
_pp_pp.prettyprinter=<module 'prettyprinter' from 'C:\\Python311\\Lib\\site-packages\\prettyprinter\\__init__.py'>
The Fix
This is caused by the following line in prettyprinter/__init__.py:
importprettyprinter.pretty_stdlib
As well as actually importing the pretty_stdlib module, this also, as a side-effect, adds a member to package prettyprinter whose value is the package prettyprinter. (Actually, I'm amazed this doesn't cause an import cycle error.)
Description
I tried to import
prettyprinter/prettyprinter.py
so that I could properly type-hint the 'context' argument to my custom printer function. However, when I did so, I was informed thatprettyprinter.prettyprinter
did not contain any attributePrettyContext
.On investigation, I discovered that
prettyprinter
(the package corresponding toprettyprinter/
) contains, on initial import, already contains a member namedprettyprinter
, but this member is actually just a circular reference to the package itself. This makes it impossible to importprettyprinter.prettyprinter
(the module corresponding toprettyprinter/prettyprinter.py
).What I Did
Output:
Output:
The Fix
This is caused by the following line in
prettyprinter/__init__.py
:As well as actually importing the
pretty_stdlib
module, this also, as a side-effect, adds a member to packageprettyprinter
whose value is the packageprettyprinter
. (Actually, I'm amazed this doesn't cause an import cycle error.)The fix is to change that line to:
Or:
Workaround
Until this bug is fixed, this is a workaround:
Note that with this workaround you can only access the
prettyprinter.py
code using_pp_pp
; trying to do_prettyprinter.prettyprinter
will not work.The text was updated successfully, but these errors were encountered: