Reusable f-strings and t-strings
Unify on one format style. With F-yeah Just add parentheses and be on your way.
Usage
Keep using f-string formatting, but when you need to re-use a template, use the
f or t function instead of the f or t literal
These two lines are equivalent
print(f'about to put {os.getpid()} to sleep')
print(f('about to put {os.getpid()} to sleep'))
# "about to put 421 to sleep"
No longer choose between copying around f-string literals or continuing to use old-style format() calls.
Instead of this
def mul(value):
assert isinstance(value, int), 'Expected value to be an integer, got {type(value)} instead'
return value * value
def pow(value):
assert isinstance(value, int), 'Expected value to be an integer, got {type(value)} instead'
return value ** value
Or this
bad_check = 'expected value to be an integer, got {type(value)} instead'
def mul(value):
assert isinstance(value, int), bad_check.format(value=value)
return value * value
def pow(value):
assert isinstance(value, int), bad_check.format(value=value)
return value ** value
You can write the template once to get consistent strings that stay in sync.
from fyeah import f
bad_check = 'Expected value to be an integer, got {type(value)} instead'
def mul(value):
assert isinstance(value, int), f(bad_check)
return value * value
def pow(value):
assert isinstance(value, int), f(bad_check)
return value ** value
Why would I use a function over the literal?
f-string literals are evaluated when they are created. This makes situations like the following impossible.
class BaseListRunner:
command = ['ls']
args = []
notify_running = '{self.__class__.__name__} is executing {self.command} with "{" ".join(self.args)}"'
def run(self):
log.debug(f(self.notify_running))
subprocess.call(self.command + args)
class AllListRunner:
def __init__(self):
self.args.append('-A')
AllListRunner().run()
# DEBUG: AllListRunnner is executing ls with "-A"
Why would I use F-yeah instead of the format() builtin?
Although the format mini-language and f-strings share a lot of syntax, they have diverged somewhat. You could use only format() for all your strings, but format() is more verbose and less flexible as compared to f-strings; enough so that f-strings were adopted into the language. Using F-yeah makes the following possible.
G_COUNT = 0
count_tracker = '{G_COUNT=} at {datetime.datetime.utcnow():%H:%M:%S}'
def acquire():
G_COUNT += 1
log.debug(f(count_tracker))
def release():
G_COUNT -= 1
log.debug(f(count_tracker))
def check():
log.debug(f(count_tracker))
return G_COUNT
Metadata
Release files for f-yeah 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| f_yeah-0.6.0.tar.gz | 9.3 kB | With provenance | Details for f_yeah-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| f_yeah-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for f_yeah-0.6.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / f_yeah-0.6.0.tar.gz
| Download URL | f_yeah-0.6.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
041e1049b58d189d6630601a176a65ec6fc14b76f88a2bd054fd182bed3229f3
|
|
BLAKE2b-256 checksum How to use checksums |
529b4005f5fce503c42019dbbf36e21e0ca322776b168abd3cd132fe62b19338
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 10, 2025.
Transparency logRelease files / f_yeah-0.6.0-py3-none-any.whl
| Download URL | f_yeah-0.6.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9d906ed552324e4737123eab97fa3723ddafad5f6dccc5ab691e182d0f95ef7
|
|
BLAKE2b-256 checksum How to use checksums |
d82b46894dad3799807d07a1e58754cdfde6e78453deef240ca4fbb34286bfad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 10, 2025.
Transparency logSecurity for f-yeah 0.6.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for f_yeah-0.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 10, 2025.
Transparency logA 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.