Skip to main content

Tedent

Keep your multi-line templated strings lookin' good :sunglasses:

This is a python version of tedent


Table of Contents


What is it?

  • A function similar to dedent just with different semantics

What does the name stand for?

  • Template string
  • indentation

names are hard


Why create it?

  • dedent didn't handle the following case like I wanted
formattedBoroughs = f"""\
[
    'Brooklyn',
    'Manhattan',
]
"""

print(
    dedent(
        f"""\
        New York boroughs
        ${formattedBoroughs}
        """
    )
)

#
# expected:
# New York boroughs
# [
#     'Brooklyn',
#     'Manhattan',
# ]
#
# actual:
#         New York boroughs
#         [
#     'Brooklyn',
#     'Manhattan',
# ]
#

Simple Usage

import tedent from 'tedent'

#
# *note the lack of the backslash
#
print(
    tedent(
        """
        This will be indented
          as you expect
        """
    )
)

# writes:
# This will be indented
#   as you expect

Questions about how the indentation works?

Because the indentation logic is both young and convoluted, please refer to the code and tests for details. The library is not that big and if you have any questions please create a github issue.


Important Usage Notes

  • First of all, this library doesn't handle tabs. I will accept a PR with support

  • Secondly, if you always use tedent like the following

    tedent(
        """
        some text
        """
    )
    

    then you shouldn't run into any issues. However we all know input can be tricky so tedent has a few input requirements in order to format your string properly.

input requirements

  • if the argument isn't a string then an error will be thrown
  • if you pass a string with three or more newlines, then
    • the first and last lines must contain only whitespace
    • the second line must contain a non-whitespace character
    • an error will be thrown if the above two conditions are not met
  • if you pass a string with fewer than 3 newlines
    • if they only contain whitespace then an empty string is returned
    • otherwise an error is thrown
  • finally, all trailing whitespace from the result is stripped

If you have questions please raise a github issue.


Test

#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py

Metadata

Release files for tedent 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tedent 0.1.5
File Size Uploaded Provenance
tedent-0.1.5.tar.gz 92.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tedent 0.1.5
File Interpreter ABI Platform
tedent-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 197.7 kB

Release files / tedent-0.1.5.tar.gz

Download URL tedent-0.1.5.tar.gz
Size 92.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3042e20657db02c0dd55a6a1df566a18280b1dd6713aeeb25f62e42aceae8a14
BLAKE2b-256 checksum
How to use checksums
2d223154eb0e3b645e35214d2ac1ee7cf5963ec2007b155093dd4fc1935175f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH

Release files / tedent-0.1.5-py3-none-any.whl

Download URL tedent-0.1.5-py3-none-any.whl
Size 105.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18a7a63a2b1fe0bf9d082fad91c25b74594a619726ed0115bbec840670f6f07c
BLAKE2b-256 checksum
How to use checksums
525797acbfdd8ef41d412c2003bf2b5543e8c49a10521f0cfda45063d6a5077a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH

Security for tedent 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page