Final 2.5.0 release (PyPi published) - Converters, construct_dict, get_function_params and more!
2.5.0 - Converters, construct_dict, get_function_params
- Includes commit 12da829 which enables 2.5.0 to function fully on Python 3.6 and 3.7 (prior to this commit
some tests only worked on 3.8+)
commit 12da829
Date: Thu Dec 5 02:39:32 2019 +0000
Add local_tests.sh, fix get_function_params on older python
- Added `local_tests.sh` for running the unit tests on multiple python versions locally
- Added `OrderedDictObject` to collections module, since python versions before 3.8 cannot reverse a normal dict.
- Add unit tests for ordered dict object
- Adjusted `get_function_params` to use the new OrderedDictObject (fixes failing tests on older python versions)
New Features / Additions
privex.helpers.common
- Added
get_function_params
- which extracts and filters a function/method or class constructor's parameters, and
outputs them in a dictionary - Added
construct_dict
, which allows you to either construct a class, or call a function using a dictionary of keyword arguments,
usingget_function_params
to detect what arguments the class/function/method can take, including any parent classes, then
filtering out any keyword arguments which would otherwise be rejected and cause a TypeError. - Added
_filter_params
, a private function used by the aforementioned functions to filter a dictionary or iterable of Parameter objects.
- Added
- New module
converters
, containing functions/classes designed to convert/parse one type into anotherconvert_datetime
converts both string date/time's as well as unix timestamps intodatetime.datetime
objects usingdateutil.parser
convert_unixtime_datetime
converts specifically UNIX epoch timestamps (can be string, int, float, Decimal etc.) intodatetime.datetime
objects,
and is used byconvert_datetime
to handle unix timestamps.convert_bool_int
converts booleansTrue
/False
as well as string / int versions into integers 1 (true) and 0 (false)convert_int_bool
is mostly an alias tois_true
, but exists for convenience and semantics (if there's a convert_bool_int, why not a convert_int_bool?)
Changes / Updates
-
Shrank the rather large copyright notice in most modules down to the small copyright block, and instead of dumping the whole X11 / MIT License text in there,
the licence block simply statesLicense: X11 / MIT
. This should make the docs a bit more readable. -
Added
python-dateutil
to thePipfile
-
For sanity reasons,
python-dateutil
has been added to theinstall_requires
(meaning it's auto-installed when you install privex-helpers). The package is relatively
small and depends on justsix
, weighing in around 500kb (python-dateutil = 468kb, six = 36kb).It may be removed and refactored into a setup.py extra at a later point, but for now it's small and commonly required enough that it can be a dependency.
-
Added
dateutil
to the sphinx intersphinx mapping -
Possibly other small changes I forgot to include
Testing
- Added new test case
TestInspectFunctions
to test_general, which tests the newget_function_params
andconstruct_dict
functions. - Added new test module
test_converters.py
which contains test cases for the new converters moduleTestConvertDate
covers date/time related converters such asconvert_datetime
andconvert_unixtime_datetime
TestConvertGeneral
covers other converters that don't fit into a specific category (or would otherwise be pointless to categorize)