Bynd is a simple way of achieving static typing in Python.
Project description
A module which allows binding values to one or more types. The most common use case would be to use bynd as if were an alias. When assigning a bynd object to a variable, the user will get runtime type checking, a bynd object in return, and access to the supplied value as well as the supplied types, where the value can be used the same way a variable would be used. The only inconvienence would be having to use the dot operator when accessing the value from the bynd object and maybe having to declare, define and instantiate a bynd object each time.
Examples:
from bynd import bynd
# Instantiate a bynd object
my_variable = bynd("some string")[str] # raises a 'byndError' if ("some string") is not a str
# In the above example, we create a variable named 'my_variable'.
# Then, we instantiate a 'bynd' object and pass it a string value ("some string").
# Finally, we bind the string value ("some string") to the type [str].
# To access the string value ("some string"), we can use the dot '.' operator.
print(my_variable.value)
# The type(s) can also be accessed the same way.
print(my_variable.types)
# bynd also does recursive type checks for collection types only.
# First, we create a variable named 'my_list' and instantiate
# another 'bynd' object passing it the of a list that contains
# another list. Secondly, we specify that the value passed should
# be of type 'list'.
my_list = bynd([1,2,3,[4,5,6]])[list]
# Thirdly, for bynd to perform recursive type checking we have to
# use a bynd method named 'inner_types' which allows us to specify
# which types the original and inner lists should contain. To specify
# such types, we need to use the 'others' keyword argument and pass it
# a list of expected types.
my_list.inner_types(others=[int]) # raises an error when either of the lists doesn't follow the type rules
# Finally, if there aren't any errors, we can access and print the lists.
print(my_list.value)
# NOTE: recursive type checking anly occurs when the 'inner_types' method is used and if it encounters a
# collection type within another collection type. This happens automatically within the 'inner_types'
# method itself.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bynd-0.1-py3-none-any.whl.
File metadata
- Download URL: bynd-0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1b576e6bd93ffa62821924ba5b179cc089e3a5b75a55743a34ffbb8b7861432
|
|
| MD5 |
add20773d94748995aed50fe946873df
|
|
| BLAKE2b-256 |
6b6589f7234c7243fbe6edb76382e77497a679de5ed6a756c7329d621d671738
|