Skip to content

Exception when executing python3 -m pprint #93366

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

Closed
YanHuaSuiMei opened this issue May 31, 2022 · 4 comments
Closed

Exception when executing python3 -m pprint #93366

YanHuaSuiMei opened this issue May 31, 2022 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@YanHuaSuiMei
Copy link

Bug report

> python -m pprint 
Traceback (most recent call last): 
  File "C:\Users\rwx1168020\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main 
    return _run_code(code, main_globals, None,
  File "C:\Users\rwx1168020\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\rwx1168020\AppData\Local\Programs\Python\Python310\lib\pprint.py", line 670, in <module>
    _perfcheck()
  File "C:\Users\rwx1168020\AppData\Local\Programs\Python\Python310\lib\pprint.py", line 645, in _perfcheck
    p._safe_repr(object, {}, None, 0, True)
TypeError: PrettyPrinter._safe_repr() takes 5 positional arguments but 6 were given

In pprint.py:

class PrettyPrinter:
   ...
   self._safe_repr(self, object, context, maxlevels, level):
   ...

...

def _perfcheck(object=None):
    import time
    if object is None:
        object = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100000
    p = PrettyPrinter()
    t1 = time.perf_counter()
    p._safe_repr(object, {}, None, 0, True)
    t2 = time.perf_counter()
    p.pformat(object)
    t3 = time.perf_counter()
    print("_safe_repr:", t2 - t1)
    print("pformat:", t3 - t2)

...

if __name__ == "__main__":
    _perfcheck()

Incorrect function call: p._safe_repr(object, {}, None, 0, True)

Your environment

Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32

@YanHuaSuiMei YanHuaSuiMei added the type-bug An unexpected behavior, bug, or error label May 31, 2022
@ericvsmith
Copy link
Member

This is a duplicate of #92546.

@YanHuaSuiMei
Copy link
Author

well . . .

@iritkatriel
Copy link
Member

well . . .

We’re discussing solutions on that issue. Can you explain why this is an actual problem for you? (That would inform our discussion).

@YanHuaSuiMei
Copy link
Author

I found the module 'pprint.py' can be executed as a module when i learned it.
When i learn, i always look docs first, code next.

It's not an actual problem for me, just want to make python better. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants