Skip to content

Commit b648e3f

Browse files
authored
Use black code style (#21)
* Use black code style * Unify code style around projects
1 parent a3739af commit b648e3f

File tree

9 files changed

+77
-90
lines changed

9 files changed

+77
-90
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Advanced descriptors
1616
:target: https://pypi.python.org/pypi/advanced-descriptors
1717
.. image:: https://img.shields.io/github/license/python-useful-helpers/advanced-descriptors.svg
1818
:target: https://raw.githubusercontent.com/python-useful-helpers/advanced-descriptors/master/LICENSE
19+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
20+
:target: https://github.com/ambv/black
1921

2022
This package includes helpers for special cases:
2123

advanced_descriptors/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
from .separate_class_method import SeparateClassMethod
1717
from .advanced_property import AdvancedProperty
1818

19-
__all__ = (
20-
'SeparateClassMethod',
21-
'AdvancedProperty',
22-
)
19+
__all__ = ("SeparateClassMethod", "AdvancedProperty")
2320

24-
__version__ = '1.0.5'
21+
__version__ = "1.0.5"
2522
__author__ = "Alexey Stepanov"
26-
__author_email__ = 'penguinolog@gmail.com'
23+
__author_email__ = "penguinolog@gmail.com"
2724
__maintainers__ = {
28-
'Alexey Stepanov': 'penguinolog@gmail.com',
29-
'Antonio Esposito': 'esposito.cloud@gmail.com',
30-
'Dennis Dmitriev': 'dis-xcom@gmail.com',
25+
"Alexey Stepanov": "penguinolog@gmail.com",
26+
"Antonio Esposito": "esposito.cloud@gmail.com",
27+
"Dennis Dmitriev": "dis-xcom@gmail.com",
3128
}
32-
__url__ = 'https://github.com/python-useful-helpers/advanced-descriptors'
29+
__url__ = "https://github.com/python-useful-helpers/advanced-descriptors"
3330
__description__ = "Advanced descriptors for special cases."
3431
__license__ = "Apache License, Version 2.0"

advanced_descriptors/advanced_property.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
import typing # noqa: F401 # pylint: disable=unused-import
1919

20-
__all__ = (
21-
'AdvancedProperty',
22-
)
20+
__all__ = ("AdvancedProperty",)
2321

2422

2523
class AdvancedProperty(object):
@@ -115,19 +113,14 @@ class AdvancedProperty(object):
115113
True
116114
"""
117115

118-
__slots__ = (
119-
'__fget',
120-
'__fset',
121-
'__fdel',
122-
'__fcget',
123-
)
116+
__slots__ = ("__fget", "__fset", "__fdel", "__fcget")
124117

125118
def __init__(
126-
self,
127-
fget=None, # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
128-
fset=None, # type: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]]
129-
fdel=None, # type: typing.Optional[typing.Callable[[typing.Any, ], None]]
130-
fcget=None, # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
119+
self,
120+
fget=None, # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
121+
fset=None, # type: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]]
122+
fdel=None, # type: typing.Optional[typing.Callable[[typing.Any, ], None]]
123+
fcget=None, # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
131124
): # type: (...) -> None
132125
"""Advanced property main entry point.
133126
@@ -148,11 +141,7 @@ def __init__(
148141

149142
self.__fcget = fcget
150143

151-
def __get__(
152-
self,
153-
instance, # type: typing.Optional[typing.Any]
154-
owner # type: typing.Any
155-
): # type: (...) -> typing.Any
144+
def __get__(self, instance, owner): # type: (typing.Optional[typing.Any], typing.Any) -> typing.Any
156145
"""Get descriptor.
157146
158147
:param instance: Owner class instance. Filled only if instance created, else None.
@@ -168,11 +157,7 @@ def __get__(
168157
return self.__fcget(owner)
169158
return self.__fget(instance)
170159

171-
def __set__(
172-
self,
173-
instance, # type: typing.Any
174-
value # type: typing.Any
175-
): # type: (...) -> None
160+
def __set__(self, instance, value): # type: (typing.Any, typing.Any) -> None
176161
"""Set descriptor.
177162
178163
:param instance: Owner class instance. Filled only if instance created, else None.
@@ -184,10 +169,7 @@ def __set__(
184169
raise AttributeError()
185170
return self.__fset(instance, value)
186171

187-
def __delete__(
188-
self,
189-
instance # type: typing.Any
190-
): # type: (...) -> None
172+
def __delete__(self, instance): # type: (typing.Any) -> None
191173
"""Delete descriptor.
192174
193175
:param instance: Owner class instance. Filled only if instance created, else None.
@@ -231,8 +213,7 @@ def fcget(self): # type: () -> typing.Optional[typing.Callable[[typing.Any, ],
231213
return self.__fcget
232214

233215
def getter(
234-
self,
235-
fget # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
216+
self, fget # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
236217
): # type: (...) -> AdvancedProperty
237218
"""Descriptor to change the getter on a property.
238219
@@ -244,8 +225,7 @@ def getter(
244225
return self
245226

246227
def setter(
247-
self,
248-
fset # type: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]]
228+
self, fset # type: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]]
249229
): # type: (...) -> AdvancedProperty
250230
"""Descriptor to change the setter on a property.
251231
@@ -257,8 +237,7 @@ def setter(
257237
return self
258238

259239
def deleter(
260-
self,
261-
fdel # type: typing.Optional[typing.Callable[[typing.Any, ], None]]
240+
self, fdel # type: typing.Optional[typing.Callable[[typing.Any, ], None]]
262241
): # type: (...) -> AdvancedProperty
263242
"""Descriptor to change the deleter on a property.
264243
@@ -270,8 +249,7 @@ def deleter(
270249
return self
271250

272251
def cgetter(
273-
self,
274-
fcget # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
252+
self, fcget # type: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
275253
): # type: (...) -> AdvancedProperty
276254
"""Descriptor to change the class wide getter on a property.
277255
@@ -283,6 +261,7 @@ def cgetter(
283261
return self
284262

285263

286-
if __name__ == '__main__': # pragma: no cover
264+
if __name__ == "__main__": # pragma: no cover
287265
import doctest
266+
288267
doctest.testmod(verbose=True)

advanced_descriptors/separate_class_method.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
import six
2121

22-
__all__ = (
23-
'SeparateClassMethod',
24-
)
22+
__all__ = ("SeparateClassMethod",)
2523

2624

2725
class SeparateClassMethod(object):
@@ -92,16 +90,11 @@ class SeparateClassMethod(object):
9290
True
9391
"""
9492

95-
__slots__ = (
96-
'__instance_method',
97-
'__class_method',
98-
)
93+
__slots__ = ("__instance_method", "__class_method")
9994

10095
def __init__(
101-
self,
102-
imeth=None, # type: typing.Optional[typing.Callable]
103-
cmeth=None, # type: typing.Optional[typing.Callable]
104-
): # type: (...) -> None
96+
self, imeth=None, cmeth=None
97+
): # type: (typing.Optional[typing.Callable], typing.Optional[typing.Callable]) -> None
10598
"""Separate class method and instance methods.
10699
107100
:param imeth: Instance method
@@ -112,11 +105,7 @@ def __init__(
112105
self.__instance_method = imeth
113106
self.__class_method = cmeth
114107

115-
def __get__(
116-
self,
117-
instance, # type: typing.Optional[typing.Any]
118-
owner # type: typing.Any
119-
): # type: (...) -> typing.Callable
108+
def __get__(self, instance, owner): # type: (typing.Optional[typing.Any], typing.Any) -> typing.Callable
120109
"""Get descriptor.
121110
122111
:rtype: typing.Callable
@@ -140,10 +129,7 @@ def instance_method(*args, **kwargs): # type: (typing.Any, typing.Any) -> typin
140129

141130
return instance_method
142131

143-
def instance_method(
144-
self,
145-
imeth # type: typing.Optional[typing.Callable]
146-
): # type: (...) -> SeparateClassMethod
132+
def instance_method(self, imeth): # type: (typing.Optional[typing.Callable]) -> SeparateClassMethod
147133
"""Descriptor to change instance method.
148134
149135
:param imeth: New instance method.
@@ -153,10 +139,7 @@ def instance_method(
153139
self.__instance_method = imeth
154140
return self
155141

156-
def class_method(
157-
self,
158-
cmeth # type: typing.Optional[typing.Callable]
159-
): # type: (...) -> SeparateClassMethod
142+
def class_method(self, cmeth): # type: (typing.Optional[typing.Callable]) -> SeparateClassMethod
160143
"""Descriptor to change class method.
161144
162145
:type cmeth: New class method.
@@ -183,6 +166,7 @@ def cmeth(self): # type: () -> typing.Optional[typing.Callable]
183166
return self.__class_method
184167

185168

186-
if __name__ == '__main__': # pragma: no cover
169+
if __name__ == "__main__": # pragma: no cover
187170
import doctest
171+
188172
doctest.testmod(verbose=True)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ requires = [
55
"setuptools >= 21.0.0,!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0", # PSF/ZPL
66
"wheel",
77
]
8+
9+
[tool.black]
10+
line-length = 120
11+
safe = true

setup.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ exclude =
3838
__init__.py,
3939
docs
4040
ignore =
41+
E203
42+
# whitespace before ':'
4143
show-pep8 = True
4244
show-source = True
4345
count = True
4446
max-line-length = 120
4547

4648
[pydocstyle]
47-
ignore = D401, D203, D213
49+
ignore =
50+
D401,
51+
D202,
52+
D203,
53+
D213
54+
# First line should be in imperative mood; try rephrasing
55+
# No blank lines allowed after function docstring
56+
# 1 blank line required before class docstring
57+
# Multi-line docstring summary should start at the second line
4858

4959
[aliases]
5060
test=pytest

test/test_advanced_property.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def val(tself):
2828
del instance.val
2929
self.assertEqual(instance.val, 0)
3030
with self.assertRaises(AttributeError):
31-
getattr(Target, 'val')
31+
getattr(Target, "val")
3232

3333
def test_02_full(self):
3434
class Target(object):
@@ -80,10 +80,10 @@ class Target(object):
8080
prop = advanced_descriptors.AdvancedProperty()
8181

8282
with self.assertRaises(AttributeError):
83-
getattr(Target, 'prop')
83+
getattr(Target, "prop")
8484

8585
with self.assertRaises(AttributeError):
86-
getattr(Target(), 'prop')
86+
getattr(Target(), "prop")
8787

8888
with self.assertRaises(AttributeError):
8989
Target().prop = 1
@@ -110,12 +110,7 @@ class Target(object):
110110
def __init__(self):
111111
self._value = 42
112112

113-
val = advanced_descriptors.AdvancedProperty(
114-
fget=getter,
115-
fset=setter,
116-
fdel=deleter,
117-
fcget=cgetter
118-
)
113+
val = advanced_descriptors.AdvancedProperty(fget=getter, fset=setter, fdel=deleter, fcget=cgetter)
119114

120115
instance = Target()
121116
self.assertEqual(instance.val, 42)
@@ -126,7 +121,7 @@ def __init__(self):
126121
self.assertEqual(instance.val, 0)
127122
self.assertEqual(Target.val, 777)
128123

129-
prop = Target.__dict__['val']
124+
prop = Target.__dict__["val"]
130125
self.assertIs(prop.fget, getter)
131126
self.assertIs(prop.fset, setter)
132127
self.assertIs(prop.fdel, deleter)

test/test_separate_class_method.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ class Target(object):
7676

7777
def __init__(tself):
7878
tself.value = 2
79-
getval = advanced_descriptors.SeparateClassMethod(
80-
imeth, cmeth
81-
)
79+
80+
getval = advanced_descriptors.SeparateClassMethod(imeth, cmeth)
8281

8382
instance = Target()
8483
self.assertEqual(instance.getval(), 2)
8584
self.assertEqual(Target.getval(), 1)
86-
descr = Target.__dict__['getval']
85+
descr = Target.__dict__["getval"]
8786
self.assertIs(descr.imeth, imeth)
8887
self.assertIs(descr.cmeth, cmeth)

tox.ini

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[tox]
77
minversion = 2.0
8-
envlist = pep8, pylint, mypy, bandit, pep257, py{27,34,35,36,37,py,py3}, py{34,35,36,37}-nocov, docs,
8+
envlist = black, pep8, pylint, mypy, bandit, pep257, py{27,34,35,36,37,py,py3}, py{34,35,36,37}-nocov, docs,
99
skipsdist = True
1010
skip_missing_interpreters = True
1111

@@ -104,13 +104,23 @@ exclude =
104104
__init__.py,
105105
docs
106106
ignore =
107+
E203
108+
# whitespace before ':'
107109
show-pep8 = True
108110
show-source = True
109111
count = True
110112
max-line-length = 120
111113

112114
[pydocstyle]
113-
ignore = D401, D203, D213
115+
ignore =
116+
D401,
117+
D202,
118+
D203,
119+
D213
120+
# First line should be in imperative mood; try rephrasing
121+
# No blank lines allowed after function docstring
122+
# 1 blank line required before class docstring
123+
# Multi-line docstring summary should start at the second line
114124

115125
[testenv:docs]
116126
deps =
@@ -127,8 +137,15 @@ deps =
127137
pipdeptree
128138
commands = pipdeptree
129139

140+
[testenv:black]
141+
deps =
142+
black
143+
usedevelop = False
144+
commands =
145+
black advanced_descriptors
146+
130147
[testenv:mypy]
131148
deps =
132-
mypy>=0.620
149+
mypy>=0.630
133150
-r{toxinidir}/CI_REQUIREMENTS.txt
134151
commands = mypy --strict advanced_descriptors

0 commit comments

Comments
 (0)