Skip to content

Commit 99f321a

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

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

.github/workflows/protocol.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Protocaol'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- gitlab/protocols/**
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- gitlab/protocols/**
14+
15+
jobs:
16+
protocol:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Fail
20+
run: /bin/false

gitlab/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import gitlab.const
1414
import gitlab.exceptions
1515
from gitlab import http_backends, utils
16+
from gitlab.protocols.client import Client
1617

1718
REDIRECT_MSG = (
1819
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -28,7 +29,7 @@
2829
)
2930

3031

31-
class Gitlab:
32+
class Gitlab(Client):
3233

3334
"""Represents a GitLab server connection.
3435

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

0 commit comments

Comments
 (0)