Skip to content

Commit 3feb3b7

Browse files
author
Liora Milbaum
committed
feat: PEP 544 – Protocols: Structural subtyping (static duck typing)
1 parent 069c6c3 commit 3feb3b7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

gitlab/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Wrapper for the GitLab API."""
22

3+
from __future__ import annotations
4+
35
import os
46
import re
57
import time
@@ -13,6 +15,7 @@
1315
import gitlab.const
1416
import gitlab.exceptions
1517
from gitlab import http_backends, utils
18+
from gitlab.protocols.client import Client
1619

1720
REDIRECT_MSG = (
1821
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -28,7 +31,7 @@
2831
)
2932

3033

31-
class Gitlab:
34+
class Gitlab(Client):
3235

3336
"""Represents a GitLab server connection.
3437

gitlab/protocols/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Defines protocols
3+
"""

gitlab/protocols/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from abc import abstractmethod
2+
from typing import Any, Dict, Optional, Protocol, Union
3+
4+
import requests
5+
6+
7+
class Client(Protocol):
8+
@abstractmethod
9+
def http_request(
10+
self,
11+
verb: str,
12+
path: str,
13+
query_data: Optional[Dict[str, Any]],
14+
post_data: Optional[Union[Dict[str, Any], bytes]],
15+
raw: bool,
16+
streamed: bool,
17+
files: Optional[Dict[str, Any]],
18+
timeout: Optional[float],
19+
obey_rate_limit: bool,
20+
retry_transient_errors: Optional[bool],
21+
max_retries: int,
22+
**kwargs: Any,
23+
) -> requests.Response:
24+
...

0 commit comments

Comments
 (0)