Skip to content

Commit 7217e7c

Browse files
committed
Add pre-commit
1 parent 41e3529 commit 7217e7c

12 files changed

+184
-137
lines changed

.pre-commit-config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: mixed-line-ending
9+
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.9.3
12+
hooks:
13+
- id: isort
14+
name: isort (python)
15+
- id: isort
16+
name: isort (cython)
17+
types: [cython]
18+
- id: isort
19+
name: isort (pyi)
20+
types: [pyi]
21+
22+
- repo: https://github.com/psf/black
23+
rev: 21.10b0
24+
hooks:
25+
- id: black
26+
# It is recommended to specify the latest version of Python
27+
# supported by your project here, or alternatively use
28+
# pre-commit's default_language_version, see
29+
# https://pre-commit.com/#top_level-default_language_version
30+
language_version: python3.7
31+
always_run: true
32+
33+
- repo: https://github.com/pre-commit/pygrep-hooks
34+
rev: v1.9.0 # Use the ref you want to point at
35+
hooks:
36+
- id: python-check-blanket-noqa
37+
- id: python-check-blanket-type-ignore
38+
- id: rst-directive-colons
39+
- id: rst-inline-touching-normal
40+
41+
- repo: https://gitlab.com/pycqa/flake8
42+
rev: 3.9.2
43+
hooks:
44+
- id: flake8
45+
additional_dependencies: [flake8-bugbear, pep8-naming, flake8-docstrings]
46+
exclude: test

advanced_descriptors/advanced_property.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,41 +121,41 @@ class AdvancedProperty(property, typing.Generic[_OwnerClassT, _ReturnT, _ClassRe
121121

122122
def __init__(
123123
self,
124-
fget: typing.Optional[typing.Callable[[_OwnerClassT], _ReturnT]] = None,
125-
fset: typing.Optional[typing.Callable[[_OwnerClassT, _ReturnT], None]] = None,
126-
fdel: typing.Optional[typing.Callable[[_OwnerClassT], None]] = None,
127-
fcget: typing.Optional[typing.Callable[[typing.Type[_OwnerClassT]], _ClassReturnT]] = None,
124+
fget: typing.Callable[[_OwnerClassT], _ReturnT] | None = None,
125+
fset: typing.Callable[[_OwnerClassT, _ReturnT], None] | None = None,
126+
fdel: typing.Callable[[_OwnerClassT], None] | None = None,
127+
fcget: typing.Callable[[type[_OwnerClassT]], _ClassReturnT] | None = None,
128128
) -> None:
129129
"""Advanced property main entry point.
130130
131131
:param fget: normal getter.
132-
:type fget: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
132+
:type fget: typing.Callable[[typing.Any, ], typing.Any] | None
133133
:param fset: normal setter.
134-
:type fset: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]]
134+
:type fset: typing.Callable[[typing.Any, typing.Any], None] | None
135135
:param fdel: normal deleter.
136-
:type fdel: typing.Optional[typing.Callable[[typing.Any, ], None]]
136+
:type fdel: typing.Callable[[typing.Any, ], None] | None
137137
:param fcget: class getter. Used as normal, if normal is None.
138-
:type fcget: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
138+
:type fcget: typing.Callable[[typing.Any, ], typing.Any] | None
139139
140140
.. note:: doc argument is not supported due to class wide getter usage.
141141
"""
142142
super().__init__(fget=fget, fset=fset, fdel=fdel)
143143

144-
self.__fcget: typing.Optional[typing.Callable[[typing.Type[_OwnerClassT]], _ClassReturnT]] = fcget
144+
self.__fcget: typing.Callable[[type[_OwnerClassT]], _ClassReturnT] | None = fcget
145145

146146
@typing.overload
147-
def __get__(self, instance: None, owner: typing.Type[_OwnerClassT]) -> _ClassReturnT:
147+
def __get__(self, instance: None, owner: type[_OwnerClassT]) -> _ClassReturnT:
148148
"""Class method."""
149149

150150
@typing.overload
151-
def __get__(self, instance: _OwnerClassT, owner: typing.Optional[typing.Type[_OwnerClassT]] = None) -> _ReturnT:
151+
def __get__(self, instance: _OwnerClassT, owner: type[_OwnerClassT] | None = None) -> _ReturnT:
152152
"""Normal method."""
153153

154154
def __get__(
155155
self,
156-
instance: typing.Optional[_OwnerClassT],
157-
owner: typing.Optional[typing.Type[_OwnerClassT]] = None,
158-
) -> typing.Union[_ClassReturnT, _ReturnT]:
156+
instance: _OwnerClassT | None,
157+
owner: type[_OwnerClassT] | None = None,
158+
) -> _ClassReturnT | _ReturnT:
159159
"""Get descriptor.
160160
161161
:param instance: Owner class instance. Filled only if instance created, else None.
@@ -169,25 +169,25 @@ def __get__(
169169
if self.__fcget is None:
170170
raise AttributeError()
171171
return self.__fcget(owner)
172-
return super().__get__(instance, owner) # type: ignore
172+
return super().__get__(instance, owner) # type: ignore[no-any-return]
173173

174174
@property
175-
def fcget(self) -> typing.Optional[typing.Callable[[typing.Type[_OwnerClassT]], _ClassReturnT]]:
175+
def fcget(self) -> typing.Callable[[type[_OwnerClassT]], _ClassReturnT] | None:
176176
"""Class wide getter instance.
177177
178178
:return: Class wide getter instance
179-
:rtype: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
179+
:rtype: typing.Callable[[typing.Any, ], typing.Any] | None
180180
"""
181181
return self.__fcget
182182

183183
def cgetter(
184184
self,
185-
fcget: typing.Optional[typing.Callable[[typing.Type[_OwnerClassT]], _ClassReturnT]],
185+
fcget: typing.Callable[[type[_OwnerClassT]], _ClassReturnT] | None,
186186
) -> AdvancedProperty[_OwnerClassT, _ReturnT, _ClassReturnT]:
187187
"""Descriptor to change the class wide getter on a property.
188188
189189
:param fcget: new class-wide getter.
190-
:type fcget: typing.Optional[typing.Callable[[typing.Any, ], typing.Any]]
190+
:type fcget: typing.Callable[[typing.Any, ], typing.Any] | None
191191
:return: AdvancedProperty
192192
:rtype: AdvancedProperty
193193
"""

0 commit comments

Comments
 (0)