python-argvalidate 0.9.0 released

Posted: 2009-03-24 16:02 [Source]
Tags:  foss python argvalidate free software

Even though I planned providing a release candidate first, which can be seen in the project's Mercurial changelog I have released python-argvalidate 0.9.0 today. Tarballs can be obtained from the Python Package Index (pypi), as usual.



So what's has changed compared to 0.8.2


Basically a lot of code has been rewritten or reviewed and modified. The most important change lies in argvalidate's internals though.
Instead of relying on Python internals, those are the func_* and func_code.* attributes of every function argvalidate uses another mechanism for obtaining the information about functions now, the inspect Module. In short this means that argvalidate should be more resistant to possible changes in the format of these attributes, because the inspect Module that ships with Python should be changed accordingly and it is unlikely that its public interface is going to break.

Which leads me straight to the next point regarding argvalidate: the public interface. The most visible change was the deprecation of the method_args, func_args and return_value decorators. These decorators are still present, but will be removed in one of the next upcoming releases of argvalidate. The functionality of method_args and func_args has been combined into the accepts decorator, whilst the returns decorator replaces return_value.

accepts now includes some magic for automatically determining whether a function or method has been decorated. Initially the plan was on using inspect's ismethod function, which did not work out as when the decorator is called for methods the method has not been bound to the class yet and looks like a simple function to ismethod. However, the magic added checks the first argument's name and decides that functions having either "self" or "cls" as their first parameter are methods, whilst everything else is a simple function.

There is more to say about accepts. Internally some checks which were done at every call to the decorated function in the past are now done only once, when the decorator is invoked. This should reduce the overhead argvalidate adds when the function (and thus the internal wrapper doing the checks) is called, but most likely will slow down decoration itself. However, decoration is only done once, whilst a function is likely to be called several times in its lifetime, which should give us an overall improvement of speed.

The documentation has been updated accordingly and can be found at the usual place.

What's up next?

There is no real further roadmap for argvalidate right now. No issues were left open, except for Python 3 testing & support. Further releases are going to be made when needed, that is when you submit a bug report and it is fixed.