Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enable mypy type checking and add type hints to gitlab/base.py#1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 2 commits intopython-gitlab:masterfromJohnVillalovos:mypy
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions.github/workflows/lint.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,3 +27,11 @@ jobs:
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v2

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install --upgrade tox
- run: tox -e mypy
2 changes: 2 additions & 0 deletions.mypy.ini
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
[mypy]
files = gitlab/*.py
63 changes: 34 additions & 29 deletionsgitlab/base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

importimportlib
fromtypingimportAny,Dict,Optional

from .clientimportGitlab,GitlabList

__all__= [
"RESTObject",
Expand All@@ -38,7 +40,7 @@ class RESTObject(object):

_id_attr="id"

def__init__(self,manager,attrs):
def__init__(self,manager:"RESTManager",attrs:Dict[str,Any])->None:
self.__dict__.update(
{
"manager":manager,
Expand All@@ -50,18 +52,18 @@ def __init__(self, manager, attrs):
self.__dict__["_parent_attrs"]=self.manager.parent_attrs
self._create_managers()

def__getstate__(self):
def__getstate__(self)->Dict[str,Any]:
state=self.__dict__.copy()
module=state.pop("_module")
state["_module_name"]=module.__name__
returnstate

def__setstate__(self,state):
def__setstate__(self,state:Dict[str,Any])->None:
module_name=state.pop("_module_name")
self.__dict__.update(state)
self.__dict__["_module"]=importlib.import_module(module_name)

def__getattr__(self,name):
def__getattr__(self,name:str)->Any:
try:
returnself.__dict__["_updated_attrs"][name]
exceptKeyError:
Expand DownExpand Up@@ -90,15 +92,15 @@ def __getattr__(self, name):
exceptKeyError:
raiseAttributeError(name)

def__setattr__(self,name,value):
def__setattr__(self,name:str,value)->None:
self.__dict__["_updated_attrs"][name]=value

def__str__(self):
def__str__(self)->str:
data=self._attrs.copy()
data.update(self._updated_attrs)
return"%s => %s"% (type(self),data)

def__repr__(self):
def__repr__(self)->str:
ifself._id_attr:
return"<%s %s:%s>"% (
self.__class__.__name__,
Expand All@@ -108,25 +110,25 @@ def __repr__(self):
else:
return"<%s>"%self.__class__.__name__

def__eq__(self,other):
def__eq__(self,other)->bool:
ifself.get_id()andother.get_id():
returnself.get_id()==other.get_id()
returnsuper(RESTObject,self)==other

def__ne__(self,other):
def__ne__(self,other)->bool:
ifself.get_id()andother.get_id():
returnself.get_id()!=other.get_id()
returnsuper(RESTObject,self)!=other

def__dir__(self):
returnsuper(RESTObject,self).__dir__()+list(self.attributes)

def__hash__(self):
def__hash__(self)->int:
ifnotself.get_id():
returnsuper(RESTObject,self).__hash__()
returnhash(self.get_id())

def_create_managers(self):
def_create_managers(self)->None:
managers=getattr(self,"_managers",None)
ifmanagersisNone:
return
Expand All@@ -136,7 +138,7 @@ def _create_managers(self):
manager=cls(self.manager.gitlab,parent=self)
self.__dict__[attr]=manager

def_update_attrs(self,new_attrs):
def_update_attrs(self,new_attrs)->None:
self.__dict__["_updated_attrs"]= {}
self.__dict__["_attrs"]=new_attrs

Expand All@@ -147,7 +149,7 @@ def get_id(self):
returngetattr(self,self._id_attr)

@property
defattributes(self):
defattributes(self)->Dict[str,Any]:
d=self.__dict__["_updated_attrs"].copy()
d.update(self.__dict__["_attrs"])
d.update(self.__dict__["_parent_attrs"])
Expand All@@ -169,7 +171,7 @@ class RESTObjectList(object):
_list: A GitlabList object
"""

def__init__(self,manager,obj_cls,_list):
def__init__(self,manager:"RESTManager",obj_cls,_list:GitlabList)->None:
"""Creates an objects list from a GitlabList.
You should not create objects of this type, but use managers list()
Expand All@@ -184,10 +186,10 @@ def __init__(self, manager, obj_cls, _list):
self._obj_cls=obj_cls
self._list=_list

def__iter__(self):
def__iter__(self)->"RESTObjectList":
returnself

def__len__(self):
def__len__(self)->int:
returnlen(self._list)

def__next__(self):
Expand All@@ -198,38 +200,38 @@ def next(self):
returnself._obj_cls(self.manager,data)

@property
defcurrent_page(self):
defcurrent_page(self)->int:
"""The current page number."""
returnself._list.current_page

@property
defprev_page(self):
defprev_page(self)->int:
"""The previous page number.
If None, the current page is the first.
"""
returnself._list.prev_page

@property
defnext_page(self):
defnext_page(self)->int:
"""The next page number.
If None, the current page is the last.
"""
returnself._list.next_page

@property
defper_page(self):
defper_page(self)->int:
"""The number of items per page."""
returnself._list.per_page

@property
deftotal_pages(self):
deftotal_pages(self)->int:
"""The total number of pages."""
returnself._list.total_pages

@property
deftotal(self):
deftotal(self)->int:
"""The total number of items."""
returnself._list.total

Expand All@@ -243,10 +245,11 @@ class RESTManager(object):
``_obj_cls``: The class of objects that will be created
"""

_path=None
_obj_cls=None
_path:Optional[str]=None
_obj_cls:Optional[Any]=None
_from_parent_attrs:Dict[str,Any]= {}

def__init__(self,gl,parent=None):
def__init__(self,gl:Gitlab,parent:Optional[RESTObject]=None)->None:
"""REST manager constructor.
Args:
Expand All@@ -259,23 +262,25 @@ def __init__(self, gl, parent=None):
self._computed_path=self._compute_path()

@property
defparent_attrs(self):
defparent_attrs(self)->Optional[Dict[str,Any]]:
returnself._parent_attrs

def_compute_path(self,path=None):
def_compute_path(self,path:Optional[str]=None)->Optional[str]:
self._parent_attrs= {}
ifpathisNone:
path=self._path
ifpathisNone:
returnNone
ifself._parentisNoneornothasattr(self,"_from_parent_attrs"):
returnpath

data= {
self_attr:getattr(self._parent,parent_attr,None)
forself_attr,parent_attrinself._from_parent_attrs.items()
forself_attr,parent_attrinself._from_parent_attrs.items()# type: ignore
}
self._parent_attrs=data
returnpath%data

@property
defpath(self):
defpath(self)->Optional[str]:
returnself._computed_path
2 changes: 1 addition & 1 deletiongitlab/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,7 +193,7 @@ def main():
# Now we build the entire set of subcommands and do the complete parsing
parser=_get_parser(gitlab.v4.cli)
try:
importargcomplete
importargcomplete# type: ignore

argcomplete.autocomplete(parser)
exceptException:
Expand Down
2 changes: 1 addition & 1 deletiongitlab/client.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,7 +25,7 @@
importgitlab.const
importgitlab.exceptions
fromgitlabimportutils
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder# type: ignore


REDIRECT_MSG= (
Expand Down
1 change: 1 addition & 0 deletionstest-requirements.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
coverage
httmock
mock
mypy
pytest
pytest-cov
responses
9 changes: 8 additions & 1 deletiontox.ini
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py39,py38,py37,py36,pep8,black,twine-check
envlist = py39,py38,py37,py36,pep8,black,twine-check,mypy

[testenv]
passenv = GITLAB_IMAGE GITLAB_TAG
Expand DownExpand Up@@ -35,6 +35,13 @@ deps = -r{toxinidir}/requirements.txt
commands =
twine check dist/*

[testenv:mypy]
basepython = python3
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
mypy {posargs}

[testenv:venv]
commands = {posargs}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp