Skip to content

Commit eed0ad3

Browse files
committed
Blackify the code base.
1 parent ea98a18 commit eed0ad3

9 files changed

+304
-210
lines changed

pyproject.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.black]
2+
line-length = 79
3+
exclude = '''
4+
/(
5+
\.eggs
6+
| \.git
7+
| \.mypy_cache
8+
| \.pytest_cache
9+
| \.tox
10+
| \.venv
11+
| _build
12+
| buck-out
13+
| build
14+
| dist
15+
)/
16+
'''

setup.py

+34-33
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,41 @@
99

1010

1111
setup(
12-
name='typet',
12+
name="typet",
1313
use_scm_version=True,
14-
description='A library of types that simplify working with typed Python.',
15-
long_description=open('README.rst').read(),
16-
author='Melissa Nuño',
17-
author_email='[email protected]',
18-
url='https://github.com/contains-io/typet',
19-
keywords=['typing', 'schema' 'validation', 'types', 'annotation',
20-
'PEP 483', 'PEP 484', 'PEP 526'],
21-
license='MIT',
22-
packages=find_packages(exclude=['tests', 'docs']),
23-
install_requires=[
24-
'pathlib2',
25-
'typingplus >= 2.2.1, < 3'
14+
description="A library of types that simplify working with typed Python.",
15+
long_description=open("README.rst").read(),
16+
author="Melissa Nuño",
17+
author_email="[email protected]",
18+
url="https://github.com/contains-io/typet",
19+
keywords=[
20+
"typing",
21+
"schema" "validation",
22+
"types",
23+
"annotation",
24+
"PEP 483",
25+
"PEP 484",
26+
"PEP 526",
2627
],
27-
setup_requires=[
28-
'pytest-runner',
29-
'setuptools_scm',
30-
],
31-
tests_require=['pytest >= 3.2'],
28+
license="MIT",
29+
packages=find_packages(exclude=["tests", "docs"]),
30+
install_requires=["pathlib2", "typingplus >= 2.2.1, < 3"],
31+
setup_requires=["pytest-runner", "setuptools_scm"],
32+
tests_require=["pytest >= 3.2"],
3233
classifiers=[
33-
'Development Status :: 3 - Alpha',
34-
'License :: OSI Approved :: MIT License',
35-
'Operating System :: OS Independent',
36-
'Programming Language :: Python',
37-
'Programming Language :: Python :: 2',
38-
'Programming Language :: Python :: 2.7',
39-
'Programming Language :: Python :: 3',
40-
'Programming Language :: Python :: 3.4',
41-
'Programming Language :: Python :: 3.5',
42-
'Programming Language :: Python :: 3.6',
43-
'Programming Language :: Python :: 3.7',
44-
'Programming Language :: Python :: Implementation :: PyPy',
45-
'Intended Audience :: Developers',
46-
'Topic :: Software Development',
47-
]
34+
"Development Status :: 3 - Alpha",
35+
"License :: OSI Approved :: MIT License",
36+
"Operating System :: OS Independent",
37+
"Programming Language :: Python",
38+
"Programming Language :: Python :: 2",
39+
"Programming Language :: Python :: 2.7",
40+
"Programming Language :: Python :: 3",
41+
"Programming Language :: Python :: 3.4",
42+
"Programming Language :: Python :: 3.5",
43+
"Programming Language :: Python :: 3.6",
44+
"Programming Language :: Python :: 3.7",
45+
"Programming Language :: Python :: Implementation :: PyPy",
46+
"Intended Audience :: Developers",
47+
"Topic :: Software Development",
48+
],
4849
)

tests/py36/test_typed_objects.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,46 @@
1111

1212
def test_strict_object():
1313
"""Simple test to verify basic StrictObject functionality."""
14+
1415
class X(typet.StrictObject):
1516
x: str
16-
x = X('initial')
17-
x.x = 'hello'
17+
18+
x = X("initial")
19+
x.x = "hello"
1820
assert isinstance(x.x, str)
19-
assert x.x == 'hello'
21+
assert x.x == "hello"
2022
with pytest.raises(TypeError):
2123
x.x = 5
2224

2325

2426
def test_object():
2527
"""Simple test to verify basic Object functionality."""
28+
2629
class X(typet.Object):
2730
x: str = None
31+
2832
x = X()
2933
x.x = 5
3034
assert isinstance(x.x, str)
31-
assert x.x == '5'
35+
assert x.x == "5"
3236

3337

3438
def test_object_failure():
3539
"""Simple test to verify basic Object failure functionality."""
40+
3641
class X(typet.Object):
3742
x: int = None
43+
3844
x = X()
3945
x.x = None
4046
with pytest.raises(TypeError):
41-
x.x = 'not an integer'
47+
x.x = "not an integer"
4248

4349

4450
def test_optional_unassigned():
4551
"""Verify that an unassigned Optional attribute is optional in __init__."""
52+
4653
class X(typet.Object):
4754
x: typing.Optional[int]
55+
4856
X()

tests/test_types.py

+42-30
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def test_bounded_type():
3131
BoundedInt(25)
3232
BoundedStr = typet.Bounded[str, 1:5, len]
3333
with pytest.raises(ValueError):
34-
BoundedStr('')
35-
assert BoundedStr('abc') == 'abc'
34+
BoundedStr("")
35+
assert BoundedStr("abc") == "abc"
3636
with pytest.raises(ValueError):
37-
BoundedStr('abcdef')
38-
assert str(BoundedInt) == 'typet.validation.Bounded[int, 10:20]'
37+
BoundedStr("abcdef")
38+
assert str(BoundedInt) == "typet.validation.Bounded[int, 10:20]"
3939
assert typet.Bounded[Any, 10:20](15) == 15
40-
assert typet.Bounded['int', 20](15) == 15
41-
assert typet.Bounded['int', 10:](15) == 15
40+
assert typet.Bounded["int", 20](15) == 15
41+
assert typet.Bounded["int", 10:](15) == 15
4242

4343

4444
def test_length_type():
@@ -49,20 +49,20 @@ def test_length_type():
4949
LengthBoundedStr = typet.Length[str, 10:20, lambda x: x]
5050
LengthBoundedStr = typet.Length[str, 1:5]
5151
with pytest.raises(ValueError):
52-
LengthBoundedStr('')
53-
assert LengthBoundedStr('a') == 'a'
54-
assert LengthBoundedStr('abcde') == 'abcde'
52+
LengthBoundedStr("")
53+
assert LengthBoundedStr("a") == "a"
54+
assert LengthBoundedStr("abcde") == "abcde"
5555
with pytest.raises(ValueError):
56-
LengthBoundedStr('abcdef')
56+
LengthBoundedStr("abcdef")
5757
LengthBoundedList = typet.Length[list, 1:1]
5858
with pytest.raises(ValueError):
5959
LengthBoundedList([])
6060
assert LengthBoundedList([1]) == [1]
6161
with pytest.raises(ValueError):
6262
LengthBoundedList([1, 2])
63-
assert str(LengthBoundedStr) == 'typet.validation.Length[str, 1:5]'
64-
assert typet.Length[Any, 1:5]('abc') == 'abc'
65-
assert typet.Length['str', 20]('abc') == 'abc'
63+
assert str(LengthBoundedStr) == "typet.validation.Length[str, 1:5]"
64+
assert typet.Length[Any, 1:5]("abc") == "abc"
65+
assert typet.Length["str", 20]("abc") == "abc"
6666

6767

6868
def test_string_type():
@@ -71,13 +71,13 @@ def test_string_type():
7171
BoundedStr = typet.String[10:20, lambda x: x]
7272
BoundedStr = typet.String[1:5]
7373
with pytest.raises(ValueError):
74-
BoundedStr('')
75-
assert BoundedStr('a') == 'a'
76-
assert BoundedStr('abcde') == 'abcde'
74+
BoundedStr("")
75+
assert BoundedStr("a") == "a"
76+
assert BoundedStr("abcde") == "abcde"
7777
with pytest.raises(ValueError):
78-
BoundedStr('abcdef')
79-
assert str(BoundedStr) == 'typet.validation.String[1:5]'
80-
assert typet.String('hello') == 'hello'
78+
BoundedStr("abcdef")
79+
assert str(BoundedStr) == "typet.validation.String[1:5]"
80+
assert typet.String("hello") == "hello"
8181

8282

8383
def test_validation_type():
@@ -90,16 +90,18 @@ def test_validation_type():
9090

9191
def test_path_types():
9292
"""Test that the supplied path validation paths work."""
93-
assert str(typet.File(__file__))== __file__
93+
assert str(typet.File(__file__)) == __file__
9494
with pytest.raises(ValueError):
9595
typet.File(str(uuid.uuid4()))
9696
assert str(typet.Dir(os.path.dirname(__file__))) == os.path.dirname(
97-
__file__)
97+
__file__
98+
)
9899
with pytest.raises(ValueError):
99100
typet.Dir(str(uuid.uuid4()))
100101
assert str(typet.ExistingPath(__file__)) == __file__
101-
assert str(typet.ExistingPath(
102-
os.path.dirname(__file__))) == os.path.dirname(__file__)
102+
assert str(
103+
typet.ExistingPath(os.path.dirname(__file__))
104+
) == os.path.dirname(__file__)
103105
with pytest.raises(ValueError):
104106
typet.ExistingPath(str(uuid.uuid4()))
105107

@@ -111,6 +113,7 @@ def test_none_type():
111113

112114
def test_singleton():
113115
"""Test that a singleton only allows a single instance of a class."""
116+
114117
@six.add_metaclass(typet.Singleton)
115118
class TestClass(object):
116119
pass
@@ -120,6 +123,7 @@ class TestClass(object):
120123

121124
def test_uninstantiable():
122125
"""Test that an uninstantiable class cannot be instantiated."""
126+
123127
@six.add_metaclass(typet.Uninstantiable)
124128
class TestClass(object):
125129
pass
@@ -134,47 +138,55 @@ def test_isinstance():
134138
assert isinstance(25, Age) is True
135139
assert isinstance(-5, Age) is False
136140
assert isinstance(200, Age) is False
137-
assert isinstance('not an int', Age) is False
141+
assert isinstance("not an int", Age) is False
138142

139143

140144
def test_strict_object():
141145
"""Simple test to verify basic StrictObject functionality."""
146+
142147
class X(typet.StrictObject):
143148
x = None # type: str
144-
x = X('initial')
145-
x.x = 'hello'
149+
150+
x = X("initial")
151+
x.x = "hello"
146152
assert is_instance(x.x, str)
147-
assert x.x == 'hello'
153+
assert x.x == "hello"
148154
with pytest.raises(TypeError):
149155
x.x = 5
150156

151157

152158
def test_object():
153159
"""Simple test to verify basic Object functionality."""
160+
154161
class X(typet.Object):
155162
x = None # type: Optional[str]
163+
156164
x = X()
157165
x.x = 5
158166
assert is_instance(x.x, str)
159-
assert x.x == '5'
167+
assert x.x == "5"
160168

161169

162170
def test_object_comments():
163171
"""Simple test to verify basic Object functionality with comment hints."""
172+
164173
class X(typet.Object):
165174
x = None # type: str
175+
166176
with pytest.raises(TypeError):
167177
X()
168178
x = X(5)
169179
assert is_instance(x.x, str)
170-
assert x.x == '5'
180+
assert x.x == "5"
171181

172182

173183
def test_object_failure():
174184
"""Simple test to verify basic Object failure functionality."""
185+
175186
class X(typet.Object):
176187
x = None # type: Optional[int]
188+
177189
x = X()
178190
x.x = None
179191
with pytest.raises(TypeError):
180-
x.x = 'not an integer'
192+
x.x = "not an integer"

typet/meta.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
from typingplus import ( # noqa: F401 pylint: disable=unused-import
2323
Any,
24-
Callable
24+
Callable,
2525
)
2626
import six
2727

2828

2929
__all__ = (
30-
'metaclass',
31-
'Singleton',
32-
'singleton',
33-
'IdempotentSingleton',
34-
'Uninstantiable',
30+
"metaclass",
31+
"Singleton",
32+
"singleton",
33+
"IdempotentSingleton",
34+
"Uninstantiable",
3535
)
3636

3737

@@ -47,17 +47,23 @@ def metaclass(*metaclasses):
4747
A decorator that will recreate the class using the specified
4848
metaclasses.
4949
"""
50+
5051
def _inner(cls):
5152
# pragma pylint: disable=unused-variable
52-
metabases = tuple(collections.OrderedDict( # noqa: F841
53-
(c, None) for c in (metaclasses + (type(cls),))
54-
).keys())
53+
metabases = tuple(
54+
collections.OrderedDict( # noqa: F841
55+
(c, None) for c in (metaclasses + (type(cls),))
56+
).keys()
57+
)
5558
# pragma pylint: enable=unused-variable
5659
_Meta = metabases[0]
5760
for base in metabases[1:]:
61+
5862
class _Meta(base, _Meta): # pylint: disable=function-redefined
5963
pass
64+
6065
return six.add_metaclass(_Meta)(cls)
66+
6167
return _inner
6268

6369

@@ -95,7 +101,8 @@ def __call__(cls, *args, **kwargs):
95101
"""Create one instance of the class and reinstantiate as necessary."""
96102
if not cls.__instance__:
97103
cls.__instance__ = super(IdempotentSingleton, cls).__call__(
98-
*args, **kwargs)
104+
*args, **kwargs
105+
)
99106
else:
100107
try:
101108
cls.__instance__.__init__(*args, **kwargs) # type: ignore
@@ -113,4 +120,4 @@ class Uninstantiable(type):
113120
def __call__(cls, *args, **kwargs):
114121
# type: (*Any, **Any) -> None
115122
"""Do not allow the class to be instantiated."""
116-
raise TypeError('Type {} cannot be instantiated.'.format(cls.__name__))
123+
raise TypeError("Type {} cannot be instantiated.".format(cls.__name__))

0 commit comments

Comments
 (0)