[Python-ideas] Possible enhancement to typing
Steve Barnes
gadgetsteve at live.co.uk
Sun Nov 5 14:18:30 EST 2017
The discussions on moving typing to a standalone library prompted me to
take a look at the documentation for typing which in turn lead to an
idea that should be reasonably simple to implement but greatly add value
to typing for some applications.
If a group of iterators were to be added to the typing module it would
be reasonably simple to automatically add and assert to any decorated
modules to ensure that such modules were always called with the
documented types.
I am thinking of decorators such as:
- @typing.assert_params_mismatch - this would provide a wrapper that
had auto-generated asserts that all the parameters were of designated types.
- @typing.debug_assert_params_mismatch - this would provide a wrapper
that had auto-generated asserts that all the parameters were of
designated types only if a DEBUG environmental variable was set or similar.
- @typing.warn_params_mismatch - this would provide a wrapper that had
auto-generated warnings issued to stderr if any of the parameters were
of not of the designated types.
- @typing.coerce_params - this would add a wrapper to attempt to
convert any mismatched parameters to the specified type(s).
I also think that this might increase the uptake of typing by giving
some clear benefits outside of documentation and static type checking.
Pushing this out for comment before considering a more formal, (PEP),
proposal.
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
---
This email has been checked for viruses by AVG.
http://www.avg.com
More information about the Python-ideas
mailing list