Skip to content

Way to properly handle lazy translations/formatting #328

@last-partizan

Description

@last-partizan

I'm thinking about how to get it right.

Currently our lazy functions just returning str, and I think about changing that to class StrPromise(Promise, str): ...

There's some problems with that, but it's better than plain str, and least disruptive. E.q. we don't need to change much code.

It allows us to catch places where we expect StrPromise, but getting str.

class Promise: ...

class StrPromise(Promise, str): ...

def gettext_lazy(v: str) -> StrPromise: ...

v1: StrPromise = StrPromise()
# Error
v2: StrPromise = ""

# Both cases ok
v3: str = ""
v4: str = StrPromise()

@sbdchd what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions