Skip to content

Fix Codeblock False Positives#3517

Open
SamuelRoettgermann wants to merge 9 commits into
python-discord:mainfrom
SamuelRoettgermann:fix-codeblock-false-positives
Open

Fix Codeblock False Positives#3517
SamuelRoettgermann wants to merge 9 commits into
python-discord:mainfrom
SamuelRoettgermann:fix-codeblock-false-positives

Conversation

@SamuelRoettgermann

@SamuelRoettgermann SamuelRoettgermann commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #3515

Fixes the described issue and adds some unit tests to cover common cases.

Also updates the bad_ticks error message to work with the new, more flexible, variable ticks approach.

ShaharNaveh
ShaharNaveh previously approved these changes Jun 6, 2026

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jb3 jb3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo, else LGTM

Comment thread bot/exts/info/codeblock/_parsing.py Outdated
Update regex comment

Co-authored-by: Joe Banks <joe@jb3.dev>
Comment thread bot/exts/info/codeblock/_parsing.py Outdated
""",
re.DOTALL | re.VERBOSE
)
_RE_CODE_BLOCK_REGEX = regex.compile(_RE_CODE_BLOCK.pattern, regex.DOTALL | regex.VERBOSE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something here or is this just a copy of _RE_CODE_BLOCK?

@SamuelRoettgermann SamuelRoettgermann Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no.

So, it is a copy, but it uses the regex module, rather than the re module, because regex.finditer allows to pass an additional overlapped parameter, which I need in the find_faulty_code_blocks function.

The reason why I didn't omit the _RE_CODE_BLOCK variable entirely just comes down to code highlighting. Let me show you with this image:
image

As you can see, at least in PyCharm, there is no default regex-highlighting when using the regex.compile function, but there is when using the re.compile function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah I missed that it's different library. I don't find syntax highlighting to be a compelling reason to create this confusion, but don't feel strongly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment explaining the decision to avoid further confusion

Comment thread bot/exts/info/codeblock/_parsing.py Outdated
Comment thread bot/exts/info/codeblock/_parsing.py Outdated
Comment thread tests/bot/exts/info/codeblock/test_parsing.py
Comment thread bot/exts/info/codeblock/_parsing.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive faulty code block detection

4 participants