Skip to content

Commit 958e633

Browse files
🏷️ update types
1 parent 76b559e commit 958e633

File tree

2 files changed

+51
-126
lines changed

2 files changed

+51
-126
lines changed

squarecloud/app.py

Lines changed: 18 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from abc import ABC
22
from io import BytesIO
3-
from typing import TYPE_CHECKING, Callable, Literal
3+
from typing import TYPE_CHECKING, Callable
4+
5+
from pydantic import PositiveInt
46

57
from .data import AppData, BackupData, FileInfo, LogsData, StatusData
68
from .errors import SquareException
@@ -159,27 +161,12 @@ def __init__(
159161
http: HTTPClient,
160162
id: str,
161163
tag: str,
162-
ram: int,
163-
lang: Literal[
164-
'javascript',
165-
'typescript',
166-
'python',
167-
'java',
168-
'rust',
169-
'go',
170-
'static',
171-
'dynamic',
172-
],
173-
cluster: Literal[
174-
'florida-free-1',
175-
'fl-haswell-4',
176-
'fl-haswell-3',
177-
'fl-haswell-2',
178-
'fl-haswell-1',
179-
'fl-vps-1',
180-
],
164+
ram: PositiveInt,
165+
lang: str,
166+
cluster: str,
181167
isWebsite: bool,
182168
desc: str | None = None,
169+
**kwargs,
183170
) -> None:
184171
"""
185172
The `__init__` function is called when the class is instantiated.
@@ -194,25 +181,9 @@ def __init__(
194181
:param http: HTTPClient: Make http requests to the api.
195182
:param id: str: The id of the app.
196183
:param tag: str: The tag of the app.
197-
:param ram: int: The amount of ram that is allocated.
198-
:param lang: Literal[
199-
'javascript',
200-
'typescript',
201-
'python',
202-
'java',
203-
'rust',
204-
'go',
205-
'static',
206-
'dynamic',
207-
]: The programming language of the app.
208-
:param cluster: Literal[
209-
'florida-free-1',
210-
'fl-haswell-4',
211-
'fl-haswell-3',
212-
'fl-haswell-2',
213-
'fl-haswell-1',
214-
'fl-vps-1',
215-
]: The cluster that the app is hosted on
184+
:param ram: PositiveInt: The amount of ram that is allocated.
185+
:param lang: str: The programming language of the app.
186+
:param cluster: str: The cluster that the app is hosted on
216187
:param isWebsite: bool: Whether if the app is a website
217188
:param desc: str | None: Define the description of the app
218189
@@ -222,25 +193,9 @@ def __init__(
222193
self._id: str = id
223194
self._tag: str = tag
224195
self._desc: str | None = desc
225-
self._ram: int = ram
226-
self._lang: Literal[
227-
'javascript',
228-
'typescript',
229-
'python',
230-
'java',
231-
'rust',
232-
'go',
233-
'static',
234-
'dynamic',
235-
] = lang
236-
self._cluster: Literal[
237-
'florida-free-1',
238-
'fl-haswell-4',
239-
'fl-haswell-3',
240-
'fl-haswell-2',
241-
'fl-haswell-1',
242-
'fl-vps-1',
243-
] = cluster
196+
self._ram: PositiveInt = ram
197+
self._lang: str = lang
198+
self._cluster: str = cluster
244199
self._isWebsite: bool = isWebsite
245200
self._client: 'Client' = client
246201
self._http: HTTPClient = http
@@ -312,67 +267,35 @@ def ram(self) -> int:
312267
the amount of ram allocated to the application
313268
314269
:return: The application ram
315-
:rtype: int
270+
:rtype: PositiveInt
316271
"""
317272
return self._ram
318273

319274
@property
320275
def lang(
321276
self,
322-
) -> Literal[
323-
'javascript',
324-
'typescript',
325-
'python',
326-
'java',
327-
'rust',
328-
'go',
329-
'static',
330-
'dynamic',
331-
]:
277+
) -> str:
332278
"""
333279
The lang function is a property that returns the application's
334280
programing language.
335281
336282
:return: The application's programing language
337-
:rtype: Literal[
338-
'javascript',
339-
'typescript',
340-
'python',
341-
'java',
342-
'rust',
343-
'go',
344-
'static',
345-
'dynamic',
346-
]
283+
:rtype: str
347284
"""
348285
return self._lang
349286

350287
@property
351288
def cluster(
352289
self,
353-
) -> Literal[
354-
'florida-free-1',
355-
'fl-haswell-4',
356-
'fl-haswell-3',
357-
'fl-haswell-2',
358-
'fl-haswell-1',
359-
'fl-vps-1',
360-
]:
290+
) -> str:
361291
"""
362292
The cluster function is a property that returns the
363293
cluster that the application is
364294
running on.
365295
366296
367297
:return: The cluster that the application is running
368-
:rtype: Literal[
369-
'florida-free-1',
370-
'fl-haswell-4',
371-
'fl-haswell-3',
372-
'fl-haswell-2',
373-
'fl-haswell-1',
374-
'fl-vps-1',
375-
]
298+
:rtype: str
376299
"""
377300
return self._cluster
378301

squarecloud/data.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from typing import Any, Dict, Literal
44

5-
from pydantic.dataclasses import dataclass
5+
from pydantic import conint
6+
from typing_extensions import TypedDict
67

8+
from pydantic.dataclasses import dataclass
79

810
# pylint: disable=too-many-instance-attributes
911
# pylint: disable=invalid-name
@@ -28,8 +30,8 @@ class PlanData:
2830
duration: Dict[str, Any] | None
2931

3032

31-
@dataclass(frozen=True)
32-
class Language:
33+
# @dataclass(frozen=True)
34+
class Language(TypedDict):
3335
name: str
3436
version: str
3537

@@ -55,9 +57,9 @@ class StatusData:
5557
:type running: bool
5658
:type storage: str
5759
:type network: Dict[str, Any]
58-
:type requests: int
59-
:type uptime: int
60-
:type time: int | None = None
60+
:type requests: conint(ge=0)
61+
:type uptime: conint(ge=0)
62+
:type time: conint(ge=0) | None = None
6163
"""
6264

6365
cpu: str
@@ -66,12 +68,12 @@ class StatusData:
6668
running: bool
6769
storage: str
6870
network: Dict[str, Any]
69-
requests: int
70-
uptime: int | None = None
71-
time: int | None = None
71+
requests: conint(ge=0)
72+
uptime: conint(ge=0) | None = None
73+
time: conint(ge=0) | None = None
7274

7375

74-
@dataclass(frozen=True)
76+
@dataclass(frozen=True, slots=True)
7577
class AppData:
7678
"""
7779
Application data class
@@ -88,7 +90,7 @@ class AppData:
8890
:type name: str
8991
:type owner: str
9092
:type cluster: str
91-
:type ram: int;
93+
:type ram: conint(ge=0);
9294
:type language: Language
9395
:type isWebsite: bool
9496
:type gitIntegration: bool
@@ -101,7 +103,7 @@ class AppData:
101103
name: str
102104
owner: str
103105
cluster: str
104-
ram: int
106+
ram: conint(ge=0)
105107
language: str
106108
cluster: str
107109
isWebsite: bool
@@ -122,13 +124,13 @@ class UserData:
122124
:ivar blocklist: Whether to user is blocked
123125
:ivar email: User email
124126
125-
:type id: int
127+
:type id: conint(ge=0)
126128
:type tag: str
127129
:type plan: PlanData
128130
:type email: str | None = None
129131
"""
130132

131-
id: int
133+
id: conint(ge=0)
132134
tag: str
133135
plan: PlanData
134136
email: str | None = None
@@ -218,17 +220,17 @@ class UploadData:
218220
:type id: str
219221
:type tag: str
220222
:type language: Language
221-
:type ram: int
222-
:type cpu: int
223+
:type ram: conint(ge=0)
224+
:type cpu: conint(ge=0)
223225
:type subdomain: str | None = None
224226
:type description: str | None = None
225227
"""
226228

227229
id: str
228230
tag: str
229231
language: Language
230-
ram: int
231-
cpu: int
232+
ram: conint(ge=0)
233+
cpu: conint(ge=0)
232234
subdomain: str | None = None
233235
description: str | None = None
234236

@@ -246,15 +248,15 @@ class FileInfo:
246248
247249
:type type: Literal['file', 'directory']
248250
:type name: str
249-
:type size: int
250-
:type lastModified: int | float
251+
:type size: conint(ge=0)
252+
:type lastModified: conint(ge=0) | float
251253
:type path: str
252254
"""
253255

254256
type: Literal['file', 'directory']
255257
name: str
256-
size: int
257-
lastModified: int | float
258+
size: conint(ge=0)
259+
lastModified: conint(ge=0) | float
258260
path: str
259261

260262

@@ -269,14 +271,14 @@ class StatisticsData:
269271
:ivar ping: Service ping
270272
:ivar time: Time
271273
272-
:type users: int
273-
:type apps: int
274-
:type websites: int
275-
:type ping: int
276-
:type time: int
274+
:type users: conint(ge=0)
275+
:type apps: conint(ge=0)
276+
:type websites: conint(ge=0)
277+
:type ping: conint(ge=0)
278+
:type time: conint(ge=0)
277279
"""
278280

279-
users: int
280-
apps: int
281-
websites: int
282-
ping: int
281+
users: conint(ge=0)
282+
apps: conint(ge=0)
283+
websites: conint(ge=0)
284+
ping: conint(ge=0)

0 commit comments

Comments
 (0)