Allow comment in dictionary#3915
Allow comment in dictionary#3915AlightSoulmate wants to merge 17 commits intocodespell-project:mainfrom
Conversation
|
Isn't this a duplicate of #2617? |
I overlooked the previous PR, sorry about that. Since the previous one appears to have stalled, I can help complete it by adding the missing tests if you're open to including this feature. |
|
I must admit I am always afraid new enhancements might impair performance. But then we don't measure performance, and reading the dictionaries shouldn't be the bottleneck in most use cases. Let's give it a try. Note that this change would disallow typos and fixes including To start with, instead of testing - [key, data] = line.split("->")
+ try:
+ key, data = line.split("->")
+ except ValueError:
+ continue |
DimitriPapadopoulos
left a comment
There was a problem hiding this comment.
Looks good, but shouldn't documentation be updated?
|
The core appeal is to make comments allowed in dictionary, including inlines comments. Comments allowed inline comments: the first hashtag must be preceded by whitespaces. Illegal comment I prefer to ensure there is a space before the hashtag, otherwise hashtags in invalid positions will be interpreted as comments, like: Is this setting acceptable ? Referring to #2068, I would also recommend not supporting typos and their correct writing form containing hashes, however we dont know whether users' customized dictionary files includes hashtags or not, so I added some code to deal with that. Code snippets for line in f:
left, pound, _ = line.partition("#")
# The first hashtag is treated as comment only if preceded by whitespace
# Otherwise it is considered part of `err` or `req`
if pound and left and left[-1] not in (' ', '\t'):
continue
line = left.strip()
# Skip empty lines or pure comment lines
if not line:
continue
try:
[key, data] = line.split("->")
except ValueError:
continueThese lines will be skipped: Blank lines are also skipped. |
Co-authored-by: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…htSoulmate/codespell into allow-comment-in-dictionary
for more information, see https://pre-commit.ci
…htSoulmate/codespell into allow-comment-in-dictionary
|
One problem is that without warning, users are less likely to notice that unsatisfactory inline comment lines are skipped, then they wouldn't have corrected them. |
Fix: #3901
Add validation to
build_dictloop incodespell/codespell_lib/_spellchecker.pyto prevent crashes mentioned in #3901 :Lines starting with
#will be recognized as comments and be ignored.Empty lines and lines missing the
->are also ignored, even though they are not supposed to exist.Manual verification:
Created
example/sample.pyto test the revision:Running on project root
No ValueError.
