Skip to main content

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 it 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 instantiate a bynd object each time.

Examples:

Importing The 'bynd' Class

# filename: bind_test.py
from Bynd.bynd import bynd

Basic 'bynd' Usage

# Instantiate a bynd object
my_variable = bynd("some string")[str] # raises a 'byndError' if the value type is not str

# In the above example, we create a variable named 'my_variable'.
# Then, we instantiated a 'bynd' object and passed it a string value.
# Finally, we've bound the string value; "some string" to the type 'str'.

# To access the value, 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_test.py output
$ python3 bynd_test.py
'my_variable.value': "some string"
'my_varaible.types': ['str']

Recursive Type Checking

# bynd can perform recursive type checking for collection types only.
# First, we instantiate another bynd object.
my_list = bynd([1,2,3,[4,5,6]])[list]

# Second, for bynd to perform recursive type checking we have to
# use a bynd method named 'inner_types' which allows us to specify
# the inner types of the collections. 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 a 'byndError' if the item types are not type 'int'

# Finally, if there aren't any errors, we can access and print the lists.
print(my_list.value)

# NOTE: recursive type checking only occurs when the 'inner_types' method is used and if
#   it encounters a collection type. Recursive type checking happens automatically within
#   the 'inner_types' method itself.
# bynd_test.py output
$ python3 bynd_test.py
'my_list': [1,2,3,[4,5,6]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bynd-0.6.post1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file bynd-0.6.post1-py3-none-any.whl.

File metadata

  • Download URL: bynd-0.6.post1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for bynd-0.6.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca6cfe97b8e066762a1653dc0af456d3e35daf91a8a5ef4858d754aa69a5f980
MD5 aecbd0a9ebd6b6f615a8c4d2125f8e99
BLAKE2b-256 275241fae34bd8a548c2656b88e1b651f166b1bc43f6a17a0578b8ce1388915d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page