Python f Codec
Wrap lonesome f-strings in print().
How to install
> python3 -m pip install f-codec
Why?
# -*- coding: f -*-
def dictionary(inst, depth=0):
ಠ_ಠ = ' ' * depth
f''' {{
'''
for name, val in inst.items():
if isinstance(val, dict):
f'''
{name} =
''' > ಠ_ಠ
dictionary(val, depth + 1)
else:
f'''
{name} = {val},
''' > ಠ_ಠ
f'''
}}
''' > ಠ_ಠ
decl = {
'a': 1,
'b': 2,
'c': { 'a': 3, 'b': 4 },
'd': { 'a': 5, 'b': { 'a': 6, 'b': 7 }, 'c': 8 },
'e': 9
}
f'''
decl =
'''
dictionary(decl)
> python3 test.py
decl = {
a = 1,
b = 2,
c = {
a = 3,
b = 4,
}
d = {
a = 5,
b = {
a = 6,
b = 7,
}
c = 8,
}
e = 9,
}
Development
> python3 -m unittest test_fcodec -v # run the regression suite
> uv build # build sdist and wheel into dist/
The test suite compares decoding against golden files in tests/golden/,
which lock in the exact transformation of known-good sources.
TODO
- true streaming support for
IncrementalDecoder(currently it buffers the whole input and decodes at once) - skip f-string if the previous line ends with "" and it isn't a comment
- skip f-string inside another string
- support for
''' > indenton a single-line f-string (only whitespace or a comment may follow the closing quotes) - support for triple-quoted strings inside an
''' > indentexpression - preserve CRLF line endings (currently normalized to LF)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
f_codec-0.1.2.tar.gz
(5.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file f_codec-0.1.2.tar.gz.
File metadata
- Download URL: f_codec-0.1.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
216bec50e3b99b217d3d1dbeb22b7b8cab20f3d9663a3e9735c1a133961a440f
|
|
| MD5 |
79e1b58aed717e58190081ebdf75e8b3
|
|
| BLAKE2b-256 |
3367ec3a8696d8919bec94931782d92d811e41804350fed50d778d117a440b4d
|
File details
Details for the file f_codec-0.1.2-py3-none-any.whl.
File metadata
- Download URL: f_codec-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e779e1b4be5d54db72e0591219a062b5c8f02c14b498967c003563774b242d
|
|
| MD5 |
e598f118ad2b379022e2ce61e75b3c1d
|
|
| BLAKE2b-256 |
c2fb24045702d96a454b1209ee6a525a41ddea9263e8b22aaa9a191823bf4da1
|