A set of useful features to make working with your code easier.
Project description
tricky - that's about python.
This module is simply a collection of useful code, utilities, and functions to simplify your work with the language and the tasks you solve.
Collection:
- Iterables module
tricky.iterables
- Typing
tricky.typing
(wip)
Examples:
Iterables
- Example of iterables.filter_item
from tricky.iterables import filter_item
numbers = range(1000)
result: int = filter_item(
numbers, # the iterable
lambda number: number == 342, # condition to get your item
None, # the default value to return, if condition not met
)
print(result)
# 342
Typing
- An example of a simple use of a TypedList:
from tricky.typing import TypedList
numbers = TypedList[int](1, 2, 3, 4, 5)
assert isinstance(numbers, (list, TypedList)) # True
But if an element with a different type is passed to the list, an exception will be thrown:
from tricky.typing import TypedList
numbers = TypedList[int](1, 2, 3, 'string', 5)
# ValueError: Passed item "string" of sequence has type <class 'str'>, but annotated type is <class 'int'>
- An example of a simple use of a AnnotatedString
from tricky.typing import AnnotatedString
expecting_value = 'example'
annotated_string = AnnotatedString['example'](expecting_value)
assert isinstance(AnnotatedString['example'](expecting_value), (str, AnnotatedString))
But if the annotated value does not match the one passed, an exception will be thrown
from tricky.typing import AnnotatedString
bad_value = 'bad_value'
annotated_string = AnnotatedString['example'](bad_value)
# ValueError: Annotated and passed values are not equal 'bad_value' != 'example'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tricky-0.0.12.tar.gz
(5.2 kB
view hashes)