connor-makowski / type_enforced

A pure python type enforcer for annotations. Enforce types in python functions and methods.
MIT License
45 stars 2 forks source link

Raise more specific exception #10

Closed danohu closed 2 years ago

danohu commented 2 years ago

Useful package! But it seems that it will always raise a generic Exception. Is there a reason not to raise either TypeError or a custom exception?

My use case is unit tests -- I want to confirm that my code throws type_enforced exceptions as appropriate, and not any other Exceptions I'm not aware of.

IMO the best choice would be a subclass of TypeError -- that way calling code can handle TypeError without knowing anything about type_enforced. But it is still possible to distinguish errors raised by Enforcer from those elsewhere in the code.

[happy to submit a PR for this if desired]

connor-makowski commented 2 years ago

This is a great point. Just released 0.0.12 to address this.

See: https://github.com/connor-makowski/type_enforced/pull/11

Let me know if this addresses your issue.

danohu commented 2 years ago

wow, fantastic! Thanks!!