Metadata-Version: 2.4
Name: ambiguous
Version: 0.5.2
Summary: flexibility when you need it
Author: Daniel Pepper
License-Expression: MIT
Project-URL: Homepage, https://github.com/dpep/py_ambiguous
Project-URL: Issues, https://github.com/dpep/py_ambiguous/issues
Project-URL: Changelog, https://github.com/dpep/py_ambiguous/blob/main/CHANGES.txt
Keywords: decorator,optional parentheses,multiget
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dynamic: license-file

ambiguous
======
flexibility when you need it


### Install
```bash
pip install ambiguous
```


### Usage

#### decorator: allow decorators to accept arguments
```python
from ambiguous import decorator


@decorator
def power(fn, exponent=2):
    """raise the wrapped function's result to an exponent"""
    return lambda x: fn(x) ** exponent


@power
def squared(x): return x

squared(2)
> 4


@power(exponent=3)
def cubed(x): return x

cubed(2)
> 8
```


#### thing_or_things: combine gets and multigets

```python
from ambiguous import thing_or_things

@thing_or_things
def itself(args):
    return {x: x for x in args}

itself(1)
> 1
itself([1, 2])
> {1: 1, 2: 2}


# specify which argument
@thing_or_things('args')
def prefix(prefix, args):
    return {x: f"{prefix}_{x}" for x in args}

prefix('abc', [1, 2])
> {1: 'abc_1', 2: 'abc_2'}
```

A list, tuple, or set is many things; anything else is one. The function must return a value for every thing.


#### optional parentheses  (warning: still experimental)
```python
import ambiguous

@ambiguous
def foo():
    return 'foo'

# the usual
foo()
> 'foo'

# ?!?
foo
> 'foo'
foo + 'abc'
> 'fooabc'


# works on classes too
@ambiguous
class Greeter:
    def __init__(self, name):
        self.name = name

    def hello(self, greeting='hello'):
        return f'{greeting} {self.name}'

Greeter('bob').hello
> 'hello bob'
Greeter('bob').hello('hi')
> 'hi bob'
```


----
[![installs](https://img.shields.io/pypi/dm/ambiguous.svg?label=installs)](https://pypi.org/project/ambiguous)
