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

django-stubs/template/library.pyi Improvements #222

Merged
merged 6 commits into from
Jan 4, 2024

Conversation

noelleleigh
Copy link

Makes use of typing.ParamSpec in Library decorators to allow decorated functions to preserve their type information.

Example:

register = template.Library()

@register.filter
def plain_text_quote(value: str):
    """Prefix each line in value with "> " to "quote" it in plain-text email bodies."""
    return indent(value, "> ", lambda _: True)

result = plain_text_quote("foo")
result # <- inferred type is `str`

The docorators have complex relationships between their arguments and return types, so they are overloaded.

Implementation reference

Copy link
Owner

@sbdchd sbdchd left a comment

Choose a reason for hiding this comment

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

Nice work! Thank you!

@kodiakhq kodiakhq bot merged commit d64cb2a into sbdchd:main Jan 4, 2024
2 checks passed
@noelleleigh noelleleigh deleted the template/library-improvements branch August 5, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants