Skip to content

Exception when executing python3 -m pprint #93366

Closed
@YanHuaSuiMei

Description

@YanHuaSuiMei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions