Skip to content

Remove Python 2 compatibility helpers: to_bytes, to_native, to_unicode #197

@lavr

Description

@lavr

These three functions in emails/utils.py are Python 2 compatibility wrappers:

  • to_native(x) — if bytes, decode to str; otherwise return as-is
  • to_unicode(x) — same, plus str(x) for non-str/bytes
  • to_bytes(x) — if str, encode to bytes; otherwise return as-is

On Python 3 they are trivial wrappers around .encode() / .decode(). They were already removed from message.py, signers.py, and utils.py itself in #194. Remaining call sites:

  • emails/loader/ (helpers.py, local_store.py, __init__.py)
  • emails/transformer.py
  • emails/store/file.py (to_bytes only)

Each call can be replaced with direct .encode() / .decode() / isinstance check. Once all call sites are migrated, the functions and their overloads can be removed from utils.py.

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