-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2b0e9a
commit 1017ed0
Showing
9 changed files
with
168 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# My ignore | ||
jupyter_notebooks/* | ||
|
||
|
||
# Temporary and binary files | ||
*~ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
============ | ||
Contributors | ||
Authors | ||
============ | ||
|
||
* stanislav <stas.prokopiev@gmail.com> | ||
* Stanislav Prokopyev <stas.prokopiev@gmail.com> | ||
|
||
Contacts | ||
======== | ||
|
||
* email: stas.prokopiev@gmail.com | ||
|
||
* `vk.com <https://vk.com/stas.prokopyev>`_ | ||
|
||
* `Facebook <https://www.facebook.com/profile.php?id=100009380530321>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Contributing | ||
============ | ||
|
||
- Fork it (<https://github.com/stas-prokopiev/char/fork>) | ||
- Create your feature branch (`git checkout -b feature/fooBar`) | ||
- Commit your changes (`git commit -am 'Add some fooBar'`) | ||
- Push to the branch (`git push origin feature/fooBar`) | ||
- Create a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
==== | ||
char | ||
==== | ||
=== | ||
cat | ||
=== | ||
|
||
|
||
Add a short description here! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +0,0 @@ | ||
# ============================================================================= | ||
# DEPRECATION WARNING: | ||
# | ||
# The file `requirements.txt` does not influence the package dependencies and | ||
# will not be automatically created in the next version of PyScaffold (v4.x). | ||
# | ||
# Please have look at the docs for better alternatives | ||
# (`Dependency Management` section). | ||
# ============================================================================= | ||
# | ||
# Add your pinned requirements so that they can be easily installed with: | ||
# pip install -r requirements.txt | ||
# Remember to also add them in setup.cfg but unpinned. | ||
# Example: | ||
# numpy==1.13.3 | ||
# scipy==1.0 | ||
# | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from pkg_resources import get_distribution, DistributionNotFound | ||
|
||
try: | ||
# Change here if project is renamed and does not equal the package name | ||
dist_name = __name__ | ||
__version__ = get_distribution(dist_name).version | ||
except DistributionNotFound: | ||
__version__ = 'unknown' | ||
finally: | ||
del get_distribution, DistributionNotFound | ||
# Standard library imports | ||
# Third party imports | ||
|
||
# Local imports | ||
from cat.main import cat | ||
|
||
check_arguments_types = cat | ||
__all__ = ["cat", "check_arguments_types"] | ||
|
||
|
||
##### | ||
# Prepare basic logger in case user is not setting it itself. | ||
##### | ||
import logging | ||
LOGGER = logging.getLogger("check_arguments_types") | ||
LOGGER.addHandler(logging.NullHandler()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Standard library imports | ||
import sys | ||
import logging | ||
# Third party imports | ||
|
||
# Local imports | ||
|
||
|
||
LOGGER = logging.getLogger("check_function_arguments") | ||
LOGGER.addHandler(logging.NullHandler()) | ||
|
||
|
||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX = {} | ||
##### | ||
# First define prefixes which are python version specific | ||
if sys.version_info[0] == 2: | ||
# basestring is parent class for str and unicode | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["str_"] = (basestring) | ||
else: | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["str_"] = (str) | ||
##### | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["bytes_"] = (bytes) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["bool_"] = (bool) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["b_"] = (bool) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["is_"] = (bool) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["has_"] = (bool) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["int_"] = (int) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["i_"] = (int) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["float_"] = (float) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["f_"] = (float) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["list_"] = (list) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["l_"] = (list) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["dict_"] = (dict) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["d_"] = (dict) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["set_"] = (set) | ||
DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX["s_"] = (set) | ||
|
||
|
||
def check_type_of_1_argument( | ||
str_function_name, | ||
str_argument_name, | ||
argument_value, | ||
tuple_types_var_can_be | ||
): | ||
"""""" | ||
if isinstance(argument_value, tuple_types_var_can_be): | ||
return | ||
str_error_message = ( | ||
"Incorrect type of variable was given to function: " + | ||
str_function_name + "\n" + | ||
"---> For variable: " + str(str_argument_name) + "\n" + | ||
"---> Were given value: " + str(argument_value) + "\n" + | ||
"---> With type: " + str(type(argument_value)) + "\n" + | ||
"---> Instead of: " + str(tuple_types_var_can_be) | ||
) | ||
raise TypeError(str_error_message) | ||
|
||
|
||
def cat( | ||
function=None, | ||
dict_tuple_types_by_prefix=None, | ||
dict_tuple_types_by_prefix_to_update_default=None, | ||
bool_is_to_skip_None_value=True, | ||
): | ||
"""""" | ||
if dict_tuple_types_by_prefix is None: | ||
dict_tuple_types_by_prefix_local = DICT_TUPLE_DEFAULT_TYPES_BY_PREFIX | ||
else: | ||
dict_tuple_types_by_prefix_local = dict_tuple_types_by_prefix | ||
|
||
def cfa_with_args(func_to_check): | ||
"""""" | ||
int_args_count = func_to_check.__code__.co_argcount | ||
list_function_arguments = \ | ||
func_to_check.__code__.co_varnames[:int_args_count] | ||
str_function_name = func_to_check.__name__ | ||
|
||
def wrapper(*args, **kwargs): | ||
dict_local_variables = locals() | ||
tuple_args = dict_local_variables['args'] | ||
dict_kwargs = dict_local_variables['kwargs'] | ||
list_tuples_to_iterate = ( | ||
list(zip(list_function_arguments, tuple_args)) + | ||
list(dict_kwargs.items()) | ||
) | ||
##### | ||
# Check arguments one by one | ||
for str_argument_name, argument_value in list_tuples_to_iterate: | ||
LOGGER.debug("Checking type of argument: %s", str_argument_name) | ||
# By default if value is None then leave this argument alone | ||
if argument_value is None and bool_is_to_skip_None_value: | ||
continue | ||
for str_prefix in dict_tuple_types_by_prefix_local: | ||
if str_argument_name.startswith(str_prefix): | ||
check_type_of_1_argument( | ||
str_function_name, | ||
str_argument_name, | ||
argument_value, | ||
dict_tuple_types_by_prefix_local[str_prefix] | ||
) | ||
|
||
##### | ||
return func_to_check(*args, **kwargs) | ||
return wrapper | ||
if function: | ||
return cfa_with_args(function) | ||
return cfa_with_args | ||
|
This file was deleted.
Oops, something went wrong.