Skip to main content

strong_typing is a Python package containing some classes to create strongly typed structures in Python

strong_typing in a few words

In Python, all variables are weakly typed, which means that a variable can take all values of any type. The Python interpreter will then infer at runtime which operations this variable can undergo depending on what it contains. This is called “type inference”.

This can be a problem in different situations

  • A function that does not receive the expected type as input

  • A variable or a class attribute whose type is changed through assignment

To avoid functions being called with bad arguments, you can use Python’s typing module) (however only with Python3). To check if a variable is not incorrectly used, you can install and run mypy module).

But if the latest is great for static check (without running the code), it does not work on the code you don’t own.

If, for instance you design a class expecting a certain type of attributes, mypy can very easily detect if you don’t mistakenly override these attributes with wrong typed data.

But if you put this class in a Python package and that someone else uses it, there is no way to be sure they will respect your attribute’s type.

To make sure they do, you would need to define a descriptor’s class for each attribute and define a setter function protecting your value against abusive set. That’s what we did :)

In the end, your class could look like this:

class MyTypedStruct(Struct):
  __ATTRIBUTES__ = [IntegerParameter(name="my_int"),
                    FloatParameter(name="my_float")]
  __DESCRIPTION__ = "A sample of class with typed attributes"

Want to know more ?

Find the complete documentation here.

Release files for strong-typing 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strong-typing 0.3.1
File Size Uploaded
strong_typing-0.3.1.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for strong-typing 0.3.1
File Interpreter ABI Platform
strong_typing-0.3.1-py2-none-any.whl Python 2 none any Details

Total release size: 37.9 kB

Release files / strong_typing-0.3.1.tar.gz

Download URL strong_typing-0.3.1.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ad1dec2f4a2fd6f7aa315e5369d8b7c7fc07ae046b5c12a2e01e3b5d038657dd
BLAKE2b-256 checksum
How to use checksums
296269c1911679e18c47bcb45eb36b09b718aa53749057998b06c2352211f4bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / strong_typing-0.3.1-py2-none-any.whl

Download URL strong_typing-0.3.1-py2-none-any.whl
Size 25.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
aa5a21800d481d3d0750e494f690de8b34c9629eb65fa7fdb3f70e33dc33be11
BLAKE2b-256 checksum
How to use checksums
69f84c0bc386b24622a80cf027de1a403c6fc5d9db463e3246e3058e0926fdc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page