opendp / opendp

The core library of differential privacy algorithms powering the OpenDP Project.
https://opendp.org
MIT License
324 stars 51 forks source link

Support `domain_of(Optional[int])` #1389

Open mccalluc opened 7 months ago

mccalluc commented 7 months ago

I'm trying to expand the docs on context.py. Added a doctest:

>>> domain_of(Optional[int])

It fails. I believe the problem is in typing.py:

        if hinted_type:
            origin, args = hinted_type
            args = [RuntimeType.parse(v, generics=generics) for v in args] or None # type: ignore[assignment]
            if origin == tuple:
                origin = 'Tuple'
            elif origin == list:
                origin = 'Vec'
            elif origin == dict:
                origin = 'HashMap'

Optional is actually a shortcut for Union with None, and we have nothing that handles that.

Rust string does work.

When this is fixed, remember to add a test to test_typing_hint.

raprasad commented 7 months ago

Note: low priority. May change with Polars