Metadata-Version: 2.4
Name: f-yeah
Version: 0.5.0
Summary: Reusable f-strings
Author-email: Jeremiah Paige <ucodery@gmail.com>
License: Copyright (c) 2019, Jeremiah Paige
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
            * Redistributions of source code must retain the above copyright
              notice, this list of conditions and the following disclaimer.
            * Redistributions in binary form must reproduce the above copyright
              notice, this list of conditions and the following disclaimer in the
              documentation and/or other materials provided with the distribution.
            * Neither the name of f-yeah nor the
              names of its contributors may be used to endorse or promote products
              derived from this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL JEREMIAH PAIGE BE LIABLE FOR ANY
        DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
        ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
        SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Home, https://github.com/ucodery/fyeah
Classifier: License :: OSI Approved :: BSD License
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dynamic: license-file

[![fyeah - reusable f-strings](https://raw.githubusercontent.com/ucodery/fyeah/master/art/logo.png)](https://github.com/ucodery/fyeah)
------

[![PyPI version](https://badge.fury.io/py/f-yeah.svg)](https://badge.fury.io/py/f-yeah)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.org/project/f-yeah/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

#### Reusable f-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` function instead of the `f` literal

These two lines are equivalent
```python
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
```python
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
```python
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.
```python
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.
```python
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.
```python
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
```
