Skip to main content

un-fstring

PyPI version

Sometimes, unfortunately, you need to write code that is compatible with Python 3.5 (e.g., to run on Ubuntu 16 or Debian 9, which will be supported until April 2021 and June 2022, respectively). Sometimes, even more unfortunately, you didn't know it needed to be when you wrote it, and you need to make it compatible post-facto.

The biggest syntax change going from 3.5 to 3.6 was the addition of f-strings. Many packages can convert old-style string formatting methods into f-strings. un-fstring does the opposite: it converts f-strings into .format() calls to preserve compatibility with Python 3.5.

To convert your code, first install un-fstring (it itself requires Python 3.6 or later):

$ pip install un-fstring

Then run it over your source code:

$ un-fstring path/to/source/directory another_file.py

un-fstring will replace f-strings with .format() calls in-place.

The --dry-run option will show a contextual diff of what un-fstring would do to your code without actually overwriting it. Run un-fstring --help to see what other options are available.

un-fstring is available as a pre-commit hook:

- repo: https://github.com/JoshKarpel/un-fstring
  rev: v0.1.2
  hooks:
    - id: un-fstring

un-fstring is not a code formatter; I recommend running black over your code afterwards with the --target-version py35 option enabled.

Though potentially useful, this is mostly a toy project based on some problems I ran into at work. If you're looking for a more robust implementation, check out f2format.

Release files for un-fstring 0.1.3

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

Source distribution (sdist)

Source distribution for un-fstring 0.1.3
File Size Uploaded
un_fstring-0.1.3.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for un-fstring 0.1.3
File Interpreter ABI Platform
un_fstring-0.1.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.6 kB

Release files / un_fstring-0.1.3.tar.gz

Download URL un_fstring-0.1.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5f8c5ba3fd1061de9fcf85653b7f73aec66f6293d3b2f5883127ff41dc819168
BLAKE2b-256 checksum
How to use checksums
4461455db06c37703f9e3420b8e877d58f914f565b551c9d103eb7fb8a0e24c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / un_fstring-0.1.3-py2.py3-none-any.whl

Download URL un_fstring-0.1.3-py2.py3-none-any.whl
Size 5.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bb8681566106cdcef437beda82f4ba4a0da1ae1a4f38542de4a6fdc5dcac763c
BLAKE2b-256 checksum
How to use checksums
b36b21697e3ee60b4e1fcb3923da895712987f202f3ae832bd06cc34a05efe2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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