Skip to content

Commit

Permalink
Revert methods typing support, update docs to reflect
Browse files Browse the repository at this point in the history
  • Loading branch information
Galtozzy committed Oct 21, 2024
1 parent 9b2725f commit fbd505a
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 293 deletions.
29 changes: 29 additions & 0 deletions docs/help/contribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contribution Guidelines

## Contribution

We welcome contributions from the community! Here’s a quick guide on how to contribute:

1. **Fork the Repository**
- Go to the <a href="https://github.com/EzyGang/py-cachify" target="_blank">py-cachify GitHub page</a> and click on "Fork."

2. **Clone Your Fork**
- Clone your forked repository to your local machine.

3. **Create a New Branch**
- Create a new branch for your feature or fix.

4. **Make Changes and Commit**
- Implement your changes and commit them with a clear message.

5. **Push to Your Fork**
- Push your changes to your fork on GitHub.

6. **Open a Pull Request**
- Navigate to the original repository and open a pull request. Describe your changes and why they are beneficial.

We appreciate your contributions and look forward to collaborating with you!

## Thank You!

Your support and contributions make a difference. Let’s build an amazing package together!
27 changes: 27 additions & 0 deletions docs/help/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Help Py-Cachify Package

Thank you for your interest in py-cachify!
Your support is crucial for the growth and improvement of this project.

Here are a few ways you can help:
## Ways to Support

1. **Try It Out**
- Download py-cachify from PyPI and test it out in your projects. Your feedback is invaluable!

2. **Star on GitHub**
- If you find py-cachify helpful, please consider <a href="https://github.com/EzyGang/py-cachify" target="_blank">starring the repository</a> on GitHub.
This not only shows your appreciation but also helps others discover the package.

3. **Share It**
- Spread the word! Share your experiences and the benefits of using py-cachify with your community on social media, forums, or blogs.

4. **Report Issues**
- If you encounter any issues or have questions, please check our <a href="https://github.com/EzyGang/py-cachify/issues" target="_blank">Issues page on GitHub</a>
where you can report bugs, ask questions, or suggest features.

## Contribution guidelines

Do you have a wonderful idea or want to help fix an issue?

Go to the [contribution guide](./contribution.md).
20 changes: 18 additions & 2 deletions docs/reference/cached.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ the cached result is returned instead of re-executing the function. This is part
| `enc_dec` | `Union[Tuple[Encoder, Decoder], None]`, optional | A tuple containing the encoding and decoding functions for the cached value. Defaults to `None`, meaning no encoding/decoding is applied. |

### Returns
- `SyncOrAsyncReset`: A wrapped function (either synchronous or asynchronous) with an additional `reset` method attached for cache management.
- `WrappedFunctionReset`: A wrapped function (either synchronous or asynchronous) with an additional `reset` method attached for cache management.
The `reset(*args, **kwargs)` method allows the user to manually reset the cache for the function using the same key.

### Method Behavior
Expand Down Expand Up @@ -68,4 +68,20 @@ await fetch_data.reset()
### Notes

- Ensure that both the serialization and deserialization functions defined in `enc_dec` are efficient to preserve optimal performance.
- If py-cachify is not initialized through `init_cachify`, a `CachifyInitError` will be raised.
- If py-cachify is not initialized through `init_cachify`, a `CachifyInitError` will be raised.

### Type Hints Remark

Currently, Python's type hints have limitations in fully capturing a function's
original signature when transitioning to a protocol-based callable in a decorator,
particularly for methods (i.e., those that include `self`).
`ParamSpec` can effectively handle argument and keyword types for functions
but doesn't translate well to methods within protocols like `WrappedFunctionReset`.
I'm staying updated on this issue and recommend checking the following resources
for more insights into ongoing discussions and proposed solutions:

- [Typeshed Pull Request #11662](https://github.com/python/typeshed/pull/11662)
- [Mypy Pull Request #17123](https://github.com/python/mypy/pull/17123)
- [Python Discussion on Allowing Self-Binding for Generic ParamSpec](https://discuss.python.org/t/allow-self-binding-for-generic-paramspec/50948)

Once any developments occur, I will quickly update the source code to incorporate the changes.
19 changes: 18 additions & 1 deletion docs/reference/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The main class, `lock`, combines both synchronous and asynchronous locking opera
## Class: ///lock///

### Description
The `lock` class manages locks using a specified key, with options for waiting and expiration. It can be used in both synchronous and asynchronous contexts.
The `lock` class manages locks using a specified key, with options for waiting and expiration.
It can be used in both synchronous and asynchronous contexts.

### Parameters

Expand Down Expand Up @@ -76,3 +77,19 @@ By using the `lock` class, you'll ensure that your function calls are properly s
### Note

- If py-cachify is not initialized through `init_cachify`, a `CachifyInitError` will be raised.

### Type Hints Remark (Decorator only application)

Currently, Python's type hints have limitations in fully capturing a function's
original signature when transitioning to a protocol-based callable in a decorator,
particularly for methods (i.e., those that include `self`).
`ParamSpec` can effectively handle argument and keyword types for functions
but doesn't translate well to methods within protocols like `WrappedFunctionLock`.
I'm staying updated on this issue and recommend checking the following resources
for more insights into ongoing discussions and proposed solutions:

- [Typeshed Pull Request #11662](https://github.com/python/typeshed/pull/11662)
- [Mypy Pull Request #17123](https://github.com/python/mypy/pull/17123)
- [Python Discussion on Allowing Self-Binding for Generic ParamSpec](https://discuss.python.org/t/allow-self-binding-for-generic-paramspec/50948)

Once any developments occur, I will quickly update the source code to incorporate the changes.
18 changes: 17 additions & 1 deletion docs/reference/once.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If the function is called while it is still locked, it can either raise an excep
| `return_on_locked` | `Any`, optional | The value to return when the function is already locked. Defaults to `None`. |

### Returns
- `SyncOrAsyncRelease`: A wrapped function (either synchronous or asynchronous) with additional methods attached for lock management, specifically:
- `WrappedFunctionLock`: A wrapped function (either synchronous or asynchronous) with additional methods attached for lock management, specifically:
- `is_locked(*args, **kwargs)`: Method to check if the function is currently locked.
- `release(*args, **kwargs)`: Method to release the lock.

Expand All @@ -50,3 +50,19 @@ async def my_async_function():

### Note
- If py-cachify is not initialized through `init_cachify`, a `CachifyInitError` will be raised.

### Type Hints Remark (Decorator only application)

Currently, Python's type hints have limitations in fully capturing a function's
original signature when transitioning to a protocol-based callable in a decorator,
particularly for methods (i.e., those that include `self`).
`ParamSpec` can effectively handle argument and keyword types for functions
but doesn't translate well to methods within protocols like `WrappedFunctionLock`.
I'm staying updated on this issue and recommend checking the following resources
for more insights into ongoing discussions and proposed solutions:

- [Typeshed Pull Request #11662](https://github.com/python/typeshed/pull/11662)
- [Mypy Pull Request #17123](https://github.com/python/mypy/pull/17123)
- [Python Discussion on Allowing Self-Binding for Generic ParamSpec](https://discuss.python.org/t/allow-self-binding-for-generic-paramspec/50948)

Once any developments occur, I will quickly update the source code to incorporate the changes.
55 changes: 55 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Release Notes

## [2.0.0](https://github.com/EzyGang/py-cachify/releases/tag/v2.0.0)

### Features & Enchancements
- **Lock improvements**: Locks are now way more versatile and support new parameters like:
- Whether to wait for the lock to expire or not (`nowait`, boolean)
- Timeouts for how long should it try to acquire a lock. (`timeout`, int | float | None)
- Expiration param to prevent deadlocks (`exp`, int | None)
- When using lock as a decorator or using `once` decorator two methods are being added to the wrapped function:
- `is_locked(*args, **kwargs)` - to check whether the lock is acquired or not
- `release(*args, **kwargs)` - to forcefully release a lock.

- More info could be found [here](./reference/lock.md).

- **File layout improved**: All internal files have been made private helping LSP's and IDE's
provide better import locations for the features py-cachify provides.

- **Type annotations are now featuring TypeIs & Protocols**: Updated type annotations are now providing even better IDE support
for you to write better code way easier, exposing all methods added on decorated functions and helping you inline.

- **Additional tests were added**

- **`cached` decorator improvements**: There is now a new method attached to the wrapped functions called
`reset(*args, **kwargs)` to allow for a quick cache resets.
- More info could be found [here](./reference/cached.md).

- **Bump dependencies**

### Breaking Changes
- **async_lock**: Async lock has been removed, you should replace it with just `lock` since it now can work in both contexts.
- **import locations**: since files were renamed and moved around quite a bit,
some import locations may not work after the 2.0.0 release, so I recommend reimporting used functions to make sure it works in your project.
### Deprecations
- **async_once, sync_once, async_cached, sync_cached**: Are now deprecated and scheduled for removal in 3.0.0
(all of those methods are just aliases for `cached` and `once`).

### Miscellaneous
- **Documentation**: Documentation was refactored and greatly improved.

I recommend checking out **[full API refernce](reference/init.md)** to get familiar with changes and new features.

## [1.1.2](https://github.com/EzyGang/py-cachify/releases/tag/v1.1.2)

### Features & Enchancements
- **Bump dependencies**
- **Docs update to include info on `init_cachify` `prefix` parameter**


## [1.1.0](https://github.com/EzyGang/py-cachify/releases/tag/v1.1.2)
### Features & Enchancements
- **Custom encoders/decoders for `cached` decorator**: `enc_dec` parameter introduced on a `cached` decorator.

### Miscellaneous
- **Documentation update**
Loading

0 comments on commit fbd505a

Please sign in to comment.