Skip to content

Allow type hinting  #219

@mohankumaru

Description

@mohankumaru

Hi,
Is there a way to include annotated assignment in the code being executed?

               sample_code = """
               a: int = 1
                """
                supported_builtins["_getattr_"] = safer_getattr
                supported_builtins["_getiter_"] = default_guarded_getiter
                supported_builtins["_iter_unpack_sequence_"] = guarded_iter_unpack_sequence
                supported_builtins["dict"] = dict
                supported_builtins["list"] = list
                byte_code = compile_restricted(
                            sample_code,
                            filename='<inline code>',
                            mode='exec'
                            )
                exec(byte_code, {'__builtins__':supported_builtins}, {'input_arg': {"a":1})

Where I am looking to add type hints to my inline code "sample_code". It will throw exception saying " AnnAssign statements are not allowed.". Is there a way to get around this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions