PyCQA / docformatter

Formats docstrings to follow PEP 257
https://pypi.python.org/pypi/docformatter
MIT License
549 stars 68 forks source link

AttributeError: 'NoneType' object has no attribute 'encoding' (from_path(filename).best().encoding) #277

Open Shuaiwu opened 9 months ago

Shuaiwu commented 9 months ago

AttributeError is caught in from_path(filename).best().encoding because from_path(filename).best() can be None ref.

Traceback (most recent call last):
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/__main__.py", line 155, in <module>
    sys.exit(main())
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/__main__.py", line 144, in main
    return _main(
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/__main__.py", line 134, in _main
    return formator.do_format_files()
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/format.py", line 257, in do_format_files
    result = self._do_format_file(filename)
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/format.py", line 286, in _do_format_file
    self.encodor.do_detect_encoding(filename)
  File "/home/xx/miniconda3/envs/py39/lib/python3.9/site-packages/docformatter/encode.py", line 59, in do_detect_encoding
    self.encoding = from_path(filename).best().encoding
AttributeError: 'NoneType' object has no attribute 'encoding'

Version

Python 3.9.17
charset-normalizer   3.3.2
docformatter 1.7.5