Skip to content

Commit 9c3bbe4

Browse files
committed
release
1 parent a8e1eeb commit 9c3bbe4

File tree

9 files changed

+141
-103
lines changed

9 files changed

+141
-103
lines changed

metablock/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .spaces import Block, Service, Space, SpaceExtension
66
from .user import User
77

8-
__version__ = "0.4.0"
8+
__version__ = "0.5.1"
99

1010
__all__ = [
1111
"Metablock",

metablock/client.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
35
import sys
4-
from typing import Dict, Optional
6+
from typing import Any
57

68
from aiohttp import ClientSession
9+
from yarl import URL
710

8-
from .components import HttpComponent, MetablockResponseError
11+
from .components import Callback, HttpComponent, MetablockResponseError
912
from .extensions import Extensions, Plugins
1013
from .orgs import Orgs
1114
from .spaces import Blocks, Domains, Space, Spaces
@@ -24,17 +27,17 @@ class Metablock(HttpComponent):
2427

2528
def __init__(
2629
self,
27-
url: Optional[str] = None,
30+
url: str | None = None,
2831
auth_key: str = "",
2932
auth_key_name: str = "x-metablock-api-key",
30-
session: Optional[ClientSession] = None,
33+
session: ClientSession | None = None,
3134
user_agent: str = DEFAULT_USER_AGENT,
3235
) -> None:
3336
self.url: str = url if url is not None else self.url
3437
self.auth_key: str = auth_key or self.auth_key
3538
self.auth_key_name = auth_key_name
36-
self.session: Optional[ClientSession] = session
37-
self.default_headers: Dict[str, str] = {
39+
self.session = session
40+
self.default_headers: dict[str, str] = {
3841
"user-agent": user_agent,
3942
"accept": "application/json",
4043
}
@@ -52,32 +55,31 @@ def __repr__(self) -> str:
5255
__str__ = __repr__
5356

5457
@property
55-
def cli(self):
58+
def cli(self) -> Metablock:
5659
return self
5760

5861
async def close(self) -> None:
5962
if self.session:
6063
await self.session.close()
6164

62-
async def __aenter__(self) -> object:
65+
async def __aenter__(self) -> Metablock:
6366
return self
6467

65-
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
68+
async def __aexit__(self, exc_type: type, exc_val: Any, exc_tb: Any) -> None:
6669
await self.close()
6770

68-
async def spec(self):
71+
async def spec(self) -> dict:
6972
return await self.execute(f"{self.url}/spec")
7073

7174
async def execute(
7275
self,
73-
url: str,
76+
url: str | URL,
7477
method: str = "",
75-
headers: Optional[Dict[str, str]] = None,
76-
callback=None,
77-
wrap=None,
78-
timeout=None,
79-
**kw,
80-
):
78+
headers: dict[str, str] | None = None,
79+
callback: Callback | None = None,
80+
wrap: Any = None,
81+
**kw: Any,
82+
) -> Any:
8183
if not self.session:
8284
self.session = ClientSession()
8385
method = method or "GET"
@@ -98,28 +100,28 @@ async def execute(
98100
data = await response.json()
99101
return wrap(data) if wrap else data
100102

101-
async def get_user(self, callback=None) -> Dict:
103+
async def get_user(self, callback: Callback | None = None) -> dict:
102104
return await self.get(f"{self.url}/user", callback=callback, wrap=self._user)
103105

104-
async def get_space(self, callback=None) -> Dict:
106+
async def get_space(self, callback: Callback | None = None) -> dict:
105107
return await self.get(f"{self.url}/space", callback=callback, wrap=self._space)
106108

107-
async def update_user(self, callback=None, **data) -> Dict:
109+
async def update_user(self, callback: Callback | None = None, **data: Any) -> dict:
108110
return await self.patch(
109111
f"{self.url}/user", json=data, callback=callback, wrap=self._user
110112
)
111113

112-
async def delete_user(self, callback=None) -> None:
114+
async def delete_user(self, callback: Callback | None = None) -> None:
113115
return await self.delete(f"{self.url}/user", callback=callback)
114116

115-
def get_default_headers(self) -> Dict[str, str]:
117+
def get_default_headers(self) -> dict[str, str]:
116118
headers = self.default_headers.copy()
117119
if self.auth_key:
118120
headers[self.auth_key_name] = self.auth_key
119121
return headers
120122

121-
def _user(self, data: Dict) -> User:
123+
def _user(self, data: dict) -> User:
122124
return User(self, data)
123125

124-
def _space(self, data: Dict) -> Space:
126+
def _space(self, data: dict) -> Space:
125127
return Space(self.spaces, data)

0 commit comments

Comments
 (0)