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. Bynd is intended use case is to be assigned to a variable. The benefits of using Bynd are static type checking at runtime and being able to access the bound value and types. A variable, in this case, can still be used the same way with one simple change; using the dot operator to access the value.

Bynd: Basic Usage

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

# Instantiates a Bynd object and binds the value "some string" to the type 'str'
my_variable = Bynd("some string")[str] 

# The above code will raise a 'ByndError' if the value is not a 'str' type

# To access the value, we can use the dot '.' operator.
print("my_variable.value: ", my_variable.value)

# The type(s) can also be accessed the same way.
print("my_variable.types: ", my_variable.types)

# Output:
#    my_variable.value: "some string"
#    my_varaible.types: {<class 'str'>}

Recursive Type Checking: A Second Layer of Security

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

# Bynd can perform recursive type checking for collection types only.
my_list = Bynd([1,2,3,[4,5,6], {'key': {'value': 21}}])[list]

# To perform recursive type checking we have to use a Bynd method
# named 'inner' which allows us to specify the inner types for all
# possible collections. These types will be used for all collections
# including nested ones, which means types need to be known in advance.
my_list.inner(str, int, list, dict)

# The above code will raise a 'ByndError' if the any of the collection
# items are not 'int', 'list', or 'dict' types

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

# Output:
#    my_list.value: [1,2,3[4,5,6], {'key': {'value': 21}}]
#    my_list.types: {<class 'dict'>, <class 'int'>, <class 'list'>, <class 'str'>}

# NOTE: recursive type checking only occurs when the 'inner' method is used and if
#   it encounters a collection type. Recursive type checking happens automatically
#   within the 'inner' method itself. It will do nothing if a collection type isn't
#   encountered. 

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bynd-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 12c8e28322ea2589f294dba62b1e56dc524089afab295a9f56f15bacf30892fc
MD5 68bcc48a7d355af745e282245133f186
BLAKE2b-256 1072b1427b2f195eb36a6ff5923347a38d26449020888280ea6b5f14711717a7

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