gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

`pyproject.toml` reading upon initialization raises TypeError exception #229

Closed markab1018 closed 3 years ago

markab1018 commented 3 years ago

Just started ipdb on a directory that happened to contain a pyproject.toml file inside to get a TypeError exception.

To reproduce this problem, pip install the latest ipdb, create an empty pyproject.toml (n.b: it does not have to empty, it should just not contain any tool section) in the directory you are launching it, and then you will observe the crash (tested with ipdb 0.13.8):

$ pip install ipdb
$ mkdir tmp
$ cd tmp
$ touch pyproject.toml
$ touch test.py
$ python -m ipdb test.py
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py:126: RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/user/.virtualenv/temp/lib/python3.8/site-packages/ipdb/__main__.py", line 327, in <module>
    main()
  File "/Users/user/.virtualenv/temp/lib/python3.8/site-packages/ipdb/__main__.py", line 299, in main
    pdb = _init_pdb(commands=commands)
  File "/Users/user/.virtualenv/temp/lib/python3.8/site-packages/ipdb/__main__.py", line 53, in _init_pdb
    context = os.getenv("IPDB_CONTEXT_SIZE", get_context_from_config())
  File "/Users/user/.virtualenv/temp/lib/python3.8/site-packages/ipdb/__main__.py", line 84, in get_context_from_config
    parser = get_config()
  File "/Users/user/.virtualenv/temp/lib/python3.8/site-packages/ipdb/__main__.py", line 181, in get_config
    if "ipdb" in toml_file.get("tool"):
TypeError: argument of type 'NoneType' is not iterable

This is almost the exact same error as described in #227 except the fix for that just traded a NameError for a TypeError.

To actually fix it would need to be

if "tool" in toml_file and "ipdb" in toml_file["tool"]:
anjos commented 3 years ago

You are right (n.b.: author of that patch).

gotcha commented 3 years ago

Thanks, released in 0.13.9