Skip to main content

Bynd is a way of introducing static typing to Python.

Project description

                            ██████╗ ██╗   ██╗███╗   ██╗██████╗ 
                            ██╔══██╗╚██╗ ██╔╝████╗  ██║██╔══██╗
                            ██████╔╝ ╚████╔╝ ██╔██╗ ██║██║  ██║
                            ██╔══██╗  ╚██╔╝  ██║╚██╗██║██║  ██║
                            ██████╔╝   ██║   ██║ ╚████║██████╔╝
                            ╚═════╝    ╚═╝   ╚═╝  ╚═══╝╚═════╝

A module which allows binding data to a single type.

Bynd's intended use, is to be assigned to a variable.

Which, in this case, the variable can still be used

exactly the same by creating a Bynd reference object

and invoking the 'byndref' method, then invoking the

'data' method. Since data is bound to a single type

the data cannot be modified causing it to become constant

and forces the programmer to create Bynd object instance

references that can be modified. Inner collection types

can be specified using the 'inner' keyword argument and

passing it a 'set' of types, to which the collection

elements will be bound.

The benefits of using Bynd are:

  1. Runtime type checking

  2. Constant Bynd object instance data

  3. Bynd object instance references

  4. Ability to access all data associated with a Bynd instance through a 'ByndRef' by invoking any of the reference methods such as: 'data', 'kind', 'inner', and 'info' after a Bynd reference is created

  5. Ability to modify reference data according to the previously specified types. This means that any new data must be inline with the types specified in the original Bynd object instance.


Bynd: Basic Usage

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

# Instantiates a Bynd object and binds the data [1,2,[3,4,5]] to the type 'list'
# and it also binds the inner elements to the type 'list' and 'int' for both lists
my_variable = Bynd([1, 2, [3, 4, 5]], list, inner={list, int})  # the data can't be changed

# The above code will raise a 'ByndError' if the data is not of type 'list'
# and if the inner elements are not of type 'list' or 'int'

# To access the data, we need to create a 'ByndRef' (a reference to a Bynd object instance).
my_varaible_ref = my_varaible.byndref()

# We can now access and print the data.
print("my_variable_ref.data: ", my_variable_ref.data())

# The 'data' and 'types' can be accessed using the 'info' method.
print("my_variable_ref.info: ", my_variable_ref.info())

# Output:
#    my_variable.data: "[1, 2, [3, 4, 5]]"
#    my_varaible.info: [([1, 2, [3, 4, 5]], <class 'list'>, {<class 'list'>, <class 'int'>})]

# Bynd reference data can also be modified as long as the data is inline with the types
# specified in the original Bynd instance (my_variable). To do so, we need to invoke the
# 'modify' method on the reference. Remember that the data is bound to the 'list' type and
# 'inner' contains the 'list' and 'int' types which means our new data needs to have at least
# one integer and/or list.
my_variable_ref.modify([300, 400, [10, 20, 30]])

# Now, lets print the new data.
print("my_variable_ref.data: ", my_variable_ref.data())
print("my_variable_ref.info: ", my_variable_ref.info())

# output:
#   my_variable_ref.data: [300, 400, [10, 20, 30]]
#   my_variable_ref.info: ([300, 400, [10, 20, 30]], list, {<class 'list'>, <class 'int'>})

NOTE:

Bynd, automatically performs recursive type checking. What that means is, for any

collection type (list, tuple, set, etc.) it encounters, collection element types

are checked against the type set passed to inner. All types need to be known or assumed

when using 'Bynd'. It also does not make use of type hints in any way and it introduces

strict yping to Python by striping some of its flexibility. Bynd, can be used along side

type hints and can be used as a way to enforce them.


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-2.3-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file bynd-2.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for bynd-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ec931750933a51864ee97ddb9f409c9e9e153b3e0503688ee2aa3c24bbc2b2a4
MD5 0db501bbd655ce9158d92e6569690cfb
BLAKE2b-256 b32ce6fa0893ffdd31de0241d4155ee27f8cc80ec9f6d6f0f516339db69a1a2b

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