Skip to content

Commit

Permalink
Stop using callable objects - Fixes: #95 (#136)
Browse files Browse the repository at this point in the history
* migrate casting from callable objects to normal functions

* migrate cast to date function

* delete old test files

* rename new test files

* use new normal functions in get_casting_function()

* linting

* Move iso functions from callable objects to normal functions

* bump version and add changelog

* Fixes from review: @ChameleonTartu

* Update changelog based on feedback from @ChameleonTartu

* Do major version bump and update changelog
  • Loading branch information
thomasborgen authored Oct 24, 2023
1 parent 47d85f2 commit 14ac652
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 603 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

## Latest Changes

## Version 3.0.0 @dataclass from attr bug and no more callable objects.

We were using `@dataclass` decorator from attr, which caused kaiba not to run when used in an environment that did not have attr installed. Thanks to @ChameleonTartu for finding and reporting the bug.

Non-private code has been changed which is why this is a major version. In the future we will make sure to have clearer line between what is private internal kaiba code and what is the interface that users will use.

### Internal

* We are now callable object free. From now on, we will only use functions.


## Version 2.0.0 Upgrade dependencies, support python 3.10, 3.11

This major version bump was needed because we upgrade `pydantic` to version 2 from version 1. This changed a lot of error messages in schema validation. If anyone was depending on those, it would break their code. In the same update we are updating a lot of other dependencies too. Most importantly going from `returns` 0.14 to 0.22. This might mean we can make the functional code look better in the future. We are also now support python 3.10 and 3.11 and test them like we do 3.8 and 3.9.
Expand Down
281 changes: 0 additions & 281 deletions kaiba/casting.py

This file was deleted.

20 changes: 20 additions & 0 deletions kaiba/casting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Callable

from returns.result import safe

from kaiba.casting._cast_to_date import cast_to_date
from kaiba.casting._cast_to_decimal import cast_to_decimal
from kaiba.casting._cast_to_integer import cast_to_integer
from kaiba.models.casting import CastToOptions


@safe
def get_casting_function(cast_to: CastToOptions) -> Callable:
"""Return casting function depending on name."""
if cast_to == CastToOptions.INTEGER:
return cast_to_integer

elif cast_to == CastToOptions.DECIMAL:
return cast_to_decimal

return cast_to_date
Loading

0 comments on commit 14ac652

Please sign in to comment.