pschanely / CrossHair

An analysis tool for Python that blurs the line between testing and type systems.
Other
996 stars 47 forks source link

Add support for NewType #259

Closed brydenfogelman closed 5 months ago

brydenfogelman commented 5 months ago

Using typing.NewType leads to the following error:

TypeError: bleh.math.Number is not a module, class, method, or function.

Example to reproduce:

from typing import NewType

Number = NewType("Number", int)

def add(a: Number, b: Number) -> Number:
    """
    post: __return__ >= 0
    """
    return Number(a + b)

if __name__ == "__main__":
    print(Number(-1) >= 0)

Is there a reason this behavior isn't supported? Is there a workaround?

pschanely commented 5 months ago

Thanks for the report! There's no reason not to support that - it's just an oversight. I've fixed it in v.0.0.54. I'd love it if you can try it out again and let me know how it goes.

brydenfogelman commented 5 months ago

This works -- thanks! I appreciate the incredibly speedy fix!

pschanely commented 5 months ago

Great. Thank you for letting me know about the issue in the first place! I hope to hear from you again about what works well for you and what doesn't!