Skip to main content

Avoiding Errors

To ensure error-free code on the Antigranular platform, developers can follow a set of guidelines and restrictions designed to promote best coding practices and minimise potential errors. By understanding and adhering to the allowed Abstract Syntax Tree (AST) nodes and the strict mypy checking rules, users can avoid common pitfalls and create robust, reliable code.

It is essential to understand permitted AST nodes such as expression evaluation, conditional statements, variable assignments, and function definitions while being mindful of blocked nodes like exception raising, asynchronous operations, and side effect-inducing statements. Additionally, using correct type annotations, ensuring type-safe method invocations, and providing appropriate type hints for variables and containers are crucial for maintaining type safety and preventing type-related bugs.

By strictly following these guidelines and utilising the whitelisted importable libraries, developers can confidently write error-free code on the Antigranular platform, while enjoying the benefits of a controlled and secure coding environment.


In the Antigranular restricted Python environment, the importation of modules is limited to a specific set of libraries, including essential data manipulation and differentially private libraries. This restriction ensures a controlled and secure environment while providing access to key modules relevant to data processing and privacy-preserving operations. The following libraries, among others, are allowed for importation:

numpy pandas op_pandas op_diffprivlib op_snsql op_snsynth op_opendp

These whitelisted libraries offer comprehensive capabilities for data manipulation, privacy-preserving operations, and statistical analysis within the Antigranular environment.


Antigranular has implemented a whitelist of allowed Abstract Syntax Tree (AST) nodes to further promote pure functional programming and minimise potential side effects. The whitelist specifically permits AST nodes that do not cause any side effects while blocking others that may introduce unpredictability or unwanted behaviour, such as raising exceptions or using async operations.

Allowed AST nodes:

  • Expression evaluation: Antigranular allows the evaluation of expressions, including arithmetic operations, logical operations, and function calls. These expressions can be safely evaluated without causing any side effects.

  • Conditional statements: Conditional statements, such as if-else statements and ternary operators, are permitted in Antigranular. You can use these constructs to conditionally execute code based on boolean expressions without introducing side effects.

  • Variable assignments: Antigranular supports variable assignments, allowing you to assign values to variables without causing side effects. This enables you to work with and manipulate data within the boundaries of the restricted environment.

  • Function definitions: You can define functions within Antigranular. Functions allow you to encapsulate logic and promote code reusability while maintaining the principles of pure functional programming.

Blocked AST nodes:

  • Exception raising: Antigranular blocks the ability to raise exceptions using the raise statement. This restriction helps maintain code stability and prevents unexpected program termination.

  • Asynchronous operations: Antigranular does not allow the usage of async and await keywords for asynchronous operations. This restriction ensures that code execution remains purely synchronous, promoting a more predictable and controlled environment.

  • Side effect-inducing statements: Antigranular blocks AST nodes that can potentially cause side effects, such as file I/O operations, network operations, or modifying global variables. By blocking these operations, Antigranular helps maintain the functional programming paradigm and minimises unexpected behaviour.

  • Classes: The use of Classes and Object Oriented Programming is currently not allowed within Antigranular!


With strict mypy checking in Antigranular, you can expect the following guidelines regarding what's allowed in terms of type safety:


  • Correct type annotations: Antigranular encourages the use of type annotations for variables, function parameters, and return values.

  • Type-safe method invocations: You are expected to use methods and functions with the correct types of arguments. Antigranular will ensure that the arguments provided match the expected types defined in the function signature.

  • Variable assignments with proper types: Variables must be assigned values of the correct type. Antigranular will enforce that the assigned value matches the declared type of the variable.

  • Type annotations for containers: When working with containers like lists, dictionaries, or tuples, Antigranular encourages using type annotations to specify the expected types of the container elements.

Not allowed:

  • Ambiguous type annotations: Antigranular strictly disallows the use of ambiguous type annotations. This means that you must provide specific and unambiguous type hints for variables, function parameters, and return values. Ambiguous types can lead to confusion and potential bugs, which are mitigated by strict mypy checking.

  • Type mismatches: Antigranular will raise an error if there is a type mismatch between the declared type and the actual value assigned to a variable, passed as a function argument, or returned from a function.

  • Missing type annotations: Antigranular strongly encourages the use of type annotations throughout the codebase. If type hints are missing, mypy will flag it as an error, ensuring that every variable and function has explicit type information.

By adhering to these guidelines, Antigranular's strict mypy checking enables you to write code with enhanced type safety and reduces the likelihood of type-related bugs.