google / google/yapf

`column_limit = 0` setting produces `ZeroDivisionError`

Open
#965 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

If I set `column_limit = 0` in my settings file, then I the following exception is raised. I was trying to disable a column limit (this would be a mildly nice feature), but regardless of whether that is allowed, I think it's safe to say that raising an exception in this circumstance is a bug.

```
Traceback (most recent call last):
File "/usr/local/bin/yapf", line 8, in
sys.exit(run_main())
File "/usr/local/lib/python3.9/site-packages/yapf/__init__.py", line 362, in run_main
sys.exit(main(sys.argv))
File "/usr/local/lib/python3.9/site-packages/yapf/__init__.py", line 126, in main
changed = FormatFiles(
File "/usr/local/lib/python3.9/site-packages/yapf/__init__.py", line 204, in FormatFiles
changed |= _FormatFile(filename, lines, style_config, no_local_style,
File "/usr/local/lib/python3.9/site-packages/yapf/__init__.py", line 227, in _FormatFile
reformatted_code, encoding, has_change = yapf_api.FormatFile(
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 94, in FormatFile
reformatted_source, changed = FormatCode(
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 166, in FormatCode
reformatted_source = reformatter.Reformat(
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/reformatter.py", line 94, in Reformat
if not _AnalyzeSolutionSpace(state):
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/reformatter.py", line 501, in _AnalyzeSolutionSpace
count = _AddNextStateToQueue(penalty, node, False, count, p_queue)
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/reformatter.py", line 529, in _AddNextStateToQueue
must_split = previous_node.state.MustSplit()
File "/usr/local/lib/python3.9/site-packages/yapf/yapflib/format_decision_state.py", line 536, in MustSplit
if (self.column_limit - self.column) / float(self.column_limit) < 0.3:
ZeroDivisionError: float division by zero
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.