aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/python/python_annotations_variable_c_runme.py
blob: 153852d05e6bf4c7b4e7cd0c39bcc41dd5382746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys

# Variable annotations for properties is only supported in python-3.6 and later (PEP 526)
if sys.version_info[0:2] >= (3, 6):
    from python_annotations_variable_c import *

    # No SWIG __annotations__ support with -builtin or -fastproxy
    annotations_supported = not(is_python_builtin() or is_python_fastproxy())

    if annotations_supported:
        ts = TemplateShort()
        anno = ts.__annotations__
        if anno != {'member_variable': 'int'}:
            raise RuntimeError("annotations mismatch: {}".format(anno))

        ts = StructWithVar()
        anno = ts.__annotations__
        if anno != {'member_variable': 'int'}:
            raise RuntimeError("annotations mismatch: {}".format(anno))

        ts = StructWithVarNotAnnotated()
        if getattr(ts, "__annotations__", None) != None:
            anno = ts.__annotations__
            raise RuntimeError("annotations mismatch: {}".format(anno))