Skip to content

Commit 2fd2f1c

Browse files
committed
2.5.0 - Converters, construct_dict, get_function_params
**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, using `get_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. - New module `converters`, containing functions/classes designed to convert/parse one type into another - `convert_datetime` converts both string date/time's as well as unix timestamps into `datetime.datetime` objects using `dateutil.parser` - `convert_unixtime_datetime` converts specifically UNIX epoch timestamps (can be string, int, float, Decimal etc.) into `datetime.datetime` objects, and is used by `convert_datetime` to handle unix timestamps. - `convert_bool_int` converts booleans `True` / `False` as well as string / int versions into integers 1 (true) and 0 (false) - `convert_int_bool` is mostly an alias to `is_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 states `License: X11 / MIT`. This should make the docs a bit more readable. - Added `python-dateutil` to the `Pipfile` - For sanity reasons, `python-dateutil` has been added to the `install_requires` (meaning it's auto-installed when you install privex-helpers). The package is relatively small and depends on just `six`, 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 new `get_function_params` and `construct_dict` functions. - Added new test module `test_converters.py` which contains test cases for the new converters module - `TestConvertDate` covers date/time related converters such as `convert_datetime` and `convert_unixtime_datetime` - `TestConvertGeneral` covers other converters that don't fit into a specific category (or would otherwise be pointless to categorize)
1 parent d254b8c commit 2fd2f1c

File tree

97 files changed

+1593
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1593
-227
lines changed

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dnspython = ">=1.16"
2626
Django = "*"
2727
MarkupSafe = ">=1.1.1"
2828
wheel = "*"
29+
python-dateutil = "*"
2930

3031
[requires]
3132
python_version = "3.8"

Pipfile.lock

+41-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,6 @@
191191
'cryptography': ('https://cryptography.io/en/latest/', None),
192192
'django': ('http://django.readthedocs.org/en/latest/', None),
193193
'semver': ('https://python-semver.readthedocs.io/en/latest/', None),
194+
'dateutil': ('https://dateutil.readthedocs.io/en/latest/', None),
194195
}
195196

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ALPHANUM
2+
========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: ALPHANUM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
C
2+
=
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: C
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CL
2+
==
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: CL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IS\_XARGS
2+
=========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: IS_XARGS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
IS\_XKWARGS
2+
===========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: IS_XKWARGS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
K
2+
=
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: K
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SAFE\_CHARS
2+
===========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: SAFE_CHARS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
T
2+
=
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: T
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
T\_PARAM
2+
========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoclass:: T_PARAM
7+
8+
9+
.. automethod:: __init__
10+
:noindex:
11+
12+
13+
Methods
14+
^^^^^^^
15+
16+
.. rubric:: Methods
17+
18+
.. autosummary::
19+
:toctree: t_param
20+
21+
~T_PARAM.__init__
22+
~T_PARAM.replace
23+
24+
25+
26+
27+
28+
Attributes
29+
^^^^^^^^^^
30+
31+
.. rubric:: Attributes
32+
33+
.. autosummary::
34+
:toctree: t_param
35+
36+
~T_PARAM.KEYWORD_ONLY
37+
~T_PARAM.POSITIONAL_ONLY
38+
~T_PARAM.POSITIONAL_OR_KEYWORD
39+
~T_PARAM.VAR_KEYWORD
40+
~T_PARAM.VAR_POSITIONAL
41+
~T_PARAM.annotation
42+
~T_PARAM.default
43+
~T_PARAM.kind
44+
~T_PARAM.name
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
T\_PARAM\_DICT
2+
==============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: T_PARAM_DICT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
T\_PARAM\_LIST
2+
==============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: T_PARAM_LIST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
USE\_ORIG\_VAR
2+
==============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoclass:: USE_ORIG_VAR
7+
8+
9+
.. automethod:: __init__
10+
:noindex:
11+
12+
13+
Methods
14+
^^^^^^^
15+
16+
.. rubric:: Methods
17+
18+
.. autosummary::
19+
:toctree: use_orig_var
20+
21+
22+
23+
24+
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
V
2+
=
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autodata:: V
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\_filter\_params
2+
================
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autofunction:: _filter_params
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
construct\_dict
2+
===============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autofunction:: construct_dict
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
get\_function\_params
2+
=====================
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autofunction:: get_function_params
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
KEYWORD\_ONLY
2+
=============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoattribute:: T_PARAM.KEYWORD_ONLY
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
POSITIONAL\_ONLY
2+
================
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoattribute:: T_PARAM.POSITIONAL_ONLY
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
POSITIONAL\_OR\_KEYWORD
2+
=======================
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoattribute:: T_PARAM.POSITIONAL_OR_KEYWORD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VAR\_KEYWORD
2+
============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoattribute:: T_PARAM.VAR_KEYWORD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VAR\_POSITIONAL
2+
===============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoattribute:: T_PARAM.VAR_POSITIONAL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\_\_init\_\_
2+
============
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. automethod:: T_PARAM.__init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
annotation
2+
==========
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoproperty:: T_PARAM.annotation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
default
2+
=======
3+
4+
.. currentmodule:: privex.helpers.common
5+
6+
.. autoproperty:: T_PARAM.default

0 commit comments

Comments
 (0)