4 ms·
from string.templatelib import Template def execute(query: Template) Should allow for static analysis to prevent this issue if you run mypy as part of you
by willcipriano 1y ago
from string.templatelib import Template
def execute(query: Template)
Should allow for static analysis to prevent this issue if you run mypy as part of your pr process.
That would be in addition to doing any runtime checks.
- benwilber0 1y agoThe first mistake we're going to see a library developer make is: def execute(query: Union[str, Template]): Maybe because they want their execute function to be backwards compatible, or just because they really do want to allow either raw strings are a template string.
- masklinn 1y ago> they really do want to allow either raw strings are a template string. I’d consider that an invalid use case: 1. You can create a template string without placeholders. 2. Even if the caller does need to pass in a string (because they’re executing from a file, or t-strings don’t support e.g. facetting) then they can just… wrap the string in a template explicitly.