Skip to content

Commit 64b3a49

Browse files
authored
Skip templating mypy_config if no placeholders exist (#124)
The solution to `if-return` on the `render_template` was selected, as the shortest one (vs modifying the `pytest_mypy_plugins/collect.py` file) Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
1 parent 5542939 commit 64b3a49

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pytest_mypy_plugins/tests/test-parametrized.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
main:2: note: Revealed type is "{{ rt }}"
4747
main:4: error: Unsupported operand types for / ("str" and "int") [operator]
4848
49+
- case: parametrized_can_skip_mypy_config_section
50+
parametrized:
51+
- val: False
52+
- val: True
53+
mypy_config: |
54+
hide_error_codes = True
55+
main: |
56+
a = {{ val }}
57+
a.lower() # E: "bool" has no attribute "lower"
4958
5059
- case: with_mypy_config
5160
parametrized:

pytest_mypy_plugins/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:
354354

355355

356356
def render_template(template: str, data: Mapping[str, Any]) -> str:
357+
if jinja2.defaults.VARIABLE_START_STRING not in template:
358+
return template
359+
357360
t: jinja2.environment.Template = _rendering_env.from_string(template)
358361
return t.render({k: v if v is not None else "None" for k, v in data.items()})
359362

0 commit comments

Comments
 (0)