Uh oh!
There was an error while loading. Please reload this page.
Allow comment in dictionary - #3915
Conversation
DimitriPapadopoulos
commented
Apr 14, 2026
Isn't this a duplicate of #2617? |
AlightSoulmate
commented
Apr 14, 2026
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
commented
Apr 14, 2026
DimitriPapadopoulos
left a comment
There was a problem hiding this comment.
Looks good, but shouldn't documentation be updated?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 forlineinf:
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`ifpoundandleftandleft[-1] notin (' ', '\t'):
continueline=left.strip()
# Skip empty lines or pure comment linesifnotline:
continuetry:
[key, data] =line.split("->")
exceptValueError:
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
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
AlightSoulmate
commented
Apr 15, 2026
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. |
peternewman
commented
Apr 19, 2026
Doing something like requiring E.g. we might want to do something with C pre-processor words which begin with a hash. I suspect they're not currently matched as words due to starting with a hash, but that's a different thing... |
DimitriPapadopoulos
commented
Apr 27, 2026
But then I fear |
larsoner
commented
Jun 5, 2026
I think going with plain Also I don't love the try/except with |
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.
