Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix renderer ignore #230

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ build-backend = "setuptools.build_meta:__legacy__"
[tool.mypy]
strict = true
warn_unused_configs = true
show_error_codes = true
enable_error_code = [
"ignore-without-code"
]
Comment on lines +8 to +11
Copy link
Member

Choose a reason for hiding this comment

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

Nice addition!


[[tool.mypy.overrides]]
# These modules do not yet have types available.
module = [
Expand Down
15 changes: 7 additions & 8 deletions readme_renderer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import re
import warnings
from typing import Any, Match, Optional
from typing import cast, Any, Dict, Callable, Match, Optional

from html import unescape

Expand All @@ -33,13 +33,13 @@
try:
import cmarkgfm
from cmarkgfm.cmark import Options as cmarkgfmOptions
variants = {
"GFM": lambda raw: cmarkgfm.github_flavored_markdown_to_html(
variants: Dict[str, Callable[[str], str]] = {
"GFM": lambda raw: cast(str, cmarkgfm.github_flavored_markdown_to_html(
Copy link
Member

Choose a reason for hiding this comment

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

Nifty trick, I'll have to remember it for the future. I've confirmed this was included in CPython since 3.5, so we're definitely safe there.

raw, options=cmarkgfmOptions.CMARK_OPT_UNSAFE
),
"CommonMark": lambda raw: cmarkgfm.markdown_to_html(
)),
"CommonMark": lambda raw: cast(str, cmarkgfm.markdown_to_html(
raw, options=cmarkgfmOptions.CMARK_OPT_UNSAFE
),
)),
}
except ImportError:
warnings.warn(_EXTRA_WARNING)
Expand All @@ -66,8 +66,7 @@ def render(
if not renderer:
return None

# The renderer is a lambda function, and mypy fails lambdas right now.
rendered = renderer(raw) # type: ignore
rendered = renderer(raw)

if not rendered:
return None
Expand Down