Skip to content

Commit e416810

Browse files
authored
Use property decorator to improve typing compatibility (#1925)
As a property these functions are expected to be accessed without the private __get_ and __set_ functions, however while the functions are typed, the property is not, and mypy shows an attribute error. As this codebase no-longer requires support for python versions without support for @property.setter(2.6?) this updates the functions to use decorators and updates the type files to reflect the attribute existence.
1 parent 54b6a97 commit e416810

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

github/MainClass.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,29 @@ def __init__(
142142
pool_size,
143143
)
144144

145-
def __get_FIX_REPO_GET_GIT_REF(self):
145+
@property
146+
def FIX_REPO_GET_GIT_REF(self):
146147
"""
147148
:type: bool
148149
"""
149150
return self.__requester.FIX_REPO_GET_GIT_REF
150151

151-
def __set_FIX_REPO_GET_GIT_REF(self, value):
152+
@FIX_REPO_GET_GIT_REF.setter
153+
def FIX_REPO_GET_GIT_REF(self, value):
152154
self.__requester.FIX_REPO_GET_GIT_REF = value
153155

154-
FIX_REPO_GET_GIT_REF = property(
155-
__get_FIX_REPO_GET_GIT_REF, __set_FIX_REPO_GET_GIT_REF
156-
)
157-
158-
def __get_per_page(self):
156+
# v2: Remove this property? Why should it be necessary to read/modify it after construction
157+
@property
158+
def per_page(self):
159159
"""
160160
:type: int
161161
"""
162162
return self.__requester.per_page
163163

164-
def __set_per_page(self, value):
164+
@per_page.setter
165+
def per_page(self, value):
165166
self.__requester.per_page = value
166167

167-
# v2: Remove this property? Why should it be necessary to read/modify it after construction
168-
per_page = property(__get_per_page, __set_per_page)
169-
170168
# v2: Provide a unified way to access values of headers of last response
171169
# v2: (and add/keep ad hoc properties for specific useful headers like rate limiting, oauth scopes, etc.)
172170
# v2: Return an instance of a class: using a tuple did not allow to add a field "resettime"

github/MainClass.pyi

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ class Github:
4141
verify: bool = ...,
4242
retry: Any = ...,
4343
) -> None: ...
44-
def __get_FIX_REPO_GET_GIT_REF(self) -> bool: ...
45-
def __set_FIX_REPO_GET_GIT_REF(self, value: bool) -> None: ...
46-
def __get_per_page(self) -> int: ...
47-
def __set_per_page(self, value: int) -> None: ...
44+
@property
45+
def FIX_REPO_GET_GIT_REF(self) -> bool: ...
46+
@FIX_REPO_GET_GIT_REF.setter
47+
def FIX_REPO_GET_GIT_REF(self, value: bool) -> None: ...
48+
@property
49+
def per_page(self) -> int: ...
50+
@per_page.setter
51+
def per_page(self, value: int) -> None: ...
4852
def create_from_raw_data(
4953
self,
5054
klass: Type[TGithubObject],

0 commit comments

Comments
 (0)