A tool to convert f-strings to .format() calls.
Project description
un-fstring
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file un_fstring-0.1.3.tar.gz
.
File metadata
- Download URL: un_fstring-0.1.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f8c5ba3fd1061de9fcf85653b7f73aec66f6293d3b2f5883127ff41dc819168 |
|
MD5 | c35b43cfc6f08cf81212ec3c3889bd56 |
|
BLAKE2b-256 | 4461455db06c37703f9e3420b8e877d58f914f565b551c9d103eb7fb8a0e24c2 |
File details
Details for the file un_fstring-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: un_fstring-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2, Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb8681566106cdcef437beda82f4ba4a0da1ae1a4f38542de4a6fdc5dcac763c |
|
MD5 | 654635784a632bee81d2fdc7d5413964 |
|
BLAKE2b-256 | b36b21697e3ee60b4e1fcb3923da895712987f202f3ae832bd06cc34a05efe2d |