GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — v1 (#16)
by Maksim
03:39
created

decorator_str()   B

Complexity

Conditions 4

Size

Total Lines 29

Duplication

Lines 29
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
dl 29
loc 29
ccs 12
cts 16
cp 0.75
crap 4.25
rs 8.5806
c 1
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3 1
import six
4 1
import logging
5
6 1
import pydash
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
def _handle_auto_doc_for_property(doc, typename):
12 1
	if doc is None:
13
		doc = '<AUTO>'
14
15 1
	if '<AUTO>' in doc:
16 1
		subst = (
17
			':getter: Get\n'
18
			'{pref}:setter: Set\n'
19
			'{pref}:rtype: {typename}'
20
		).format(
21
			typename=typename,
22
			pref='\t\t',
23
		)
24 1
		doc = doc.replace('<AUTO>', subst)
25
26 1
	return doc
27
28
29 1
def dict_enum_property(path, enumtype):
30 1
	def decorator(fn):
31
32 1
		def _get(self):
33 1
			v = pydash.get(self.raw, path)
34
35 1
			if v is None:
36
				return None
37
38 1
			return enumtype(v)
39
40 1
		def _set(self, value):
41 1
			if isinstance(value, enumtype):
42 1
				value = value.value
43 1
			value = fn(self, value)
44 1
			pydash.set_(self.raw, path, value)
45
46 1
			return enumtype(value)
47
48 1
		doc = _handle_auto_doc_for_property(
49
			fn.__doc__,
50
			'~{mod}.{nm}'.format(
51
				mod=enumtype.__module__,
52
				nm=enumtype.__name__,
53
			)
54
		)
55
56 1
		p = property(_get, _set, None, doc)
57 1
		return p
58 1
	return decorator
59
60
61
# TODO: test over unicode in python 2
62 1
def dict_property(path, anytype):
63
	"""
64
	Creates new strict-typed PROPERTY for classes inherited from :class:`dict`
65
	"""
66
67 1 View Code Duplication
	def decorator_str(fn):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
68
69 1
		def _get(self):
70 1
			v = pydash.get(self.raw, path)
71
72 1
			if v is None:
73 1
				return None
74
75 1
			return six.text_type(v)
76
77 1
		def _set(self, value):
78
			v = six.text_type(value)
79
			v = fn(self, v)
80
			pydash.set_(self.raw, path, v)
81
82
			return v
83
84 1
		doc = fn.__doc__
85
86 1
		typename = type(six.text_type('')).__name__
87
88 1
		doc = _handle_auto_doc_for_property(
89
			fn.__doc__,
90
			typename
91
		)
92
93 1
		p = property(_get, _set, None, doc)
94
95 1
		return p
96
97 1 View Code Duplication
	def decorator_other(fn):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
98
99 1
		def _get(self):
100 1
			v = pydash.get(self.raw, path)
101
102 1
			if v is None:
103
				return None
104
105 1
			return anytype(v)
106
107 1
		def _set(self, value):
108
			v = fn(self, value)
109
			pydash.set_(self.raw, path, v)
110
111
			return v
112
113 1
		doc = fn.__doc__
114
115 1
		if doc is None:
116
			doc = '<AUTO>'
117
118 1
		typename = anytype.__name__
119
120 1
		doc = _handle_auto_doc_for_property(
121
			fn.__doc__,
122
			typename
123
		)
124
125 1
		p = property(_get, _set, None, doc)
126
127 1
		return p
128
129 1
	if anytype == str:
130 1
		return decorator_str
131
132
	return decorator_other
133