Skip to content

Repository files navigation

Python f Codec

Wrap lonesome f-strings in print().

How to install

> python3 -m pip install f-codec

Why?

# -*- coding: f -*-defdictionary(inst, depth=0):
ಠ_ಠ=' '*depthf''' {{'''forname, valininst.items():
ifisinstance(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 ''' > indent on a single-line f-string (only whitespace or a comment may follow the closing quotes)
  • support for triple-quoted strings inside an ''' > indent expression
  • preserve CRLF line endings (currently normalized to LF)

About

Python 'f' Codec

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages