Skip to content

Commit bc02ebd

Browse files
committed
additional ruff rules to ensure clean project
1 parent d990151 commit bc02ebd

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

mystbin/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class Client:
5656
def __init__(self, *, session: ClientSession | None = None, root_url: str = "https://mystb.in") -> None:
5757
self.http: HTTPClient = HTTPClient(session=session, root_url=root_url)
5858

59-
async def __aenter__(self) -> Self: # noqa: D105
59+
async def __aenter__(self) -> Self:
6060
return self
6161

62-
async def __aexit__( # noqa: D105
62+
async def __aexit__(
6363
self,
6464
exc_cls: type[BaseException] | None,
6565
exc_value: BaseException | None,

mystbin/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030

3131
class APIException(Exception):
32+
"""Non-specific API error and http status code."""
33+
3234
def __init__(self, *, response: ClientResponse, status_code: int) -> None:
3335
self.response = response
3436
self.status_code = status_code

mystbin/paste.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class File:
4444
"""Represents a single file within a mystb.in paste.
4545
4646
Attributes
47-
-----------
47+
----------
4848
filename: :class:`str`
4949
The file's name.
5050
content: :class:`str`
@@ -74,7 +74,7 @@ def lines_of_code(self) -> int:
7474
"""The total lines of code this file has.
7575
7676
Returns
77-
--------
77+
-------
7878
:class:`int`
7979
"""
8080
return self._lines_of_code
@@ -84,7 +84,7 @@ def character_count(self) -> int:
8484
"""The total character count of this file.
8585
8686
Returns
87-
--------
87+
-------
8888
:class:`int`
8989
"""
9090
return self._character_count
@@ -94,7 +94,7 @@ def annotation(self) -> str:
9494
"""The files annotation.
9595
9696
Returns
97-
--------
97+
-------
9898
:class:`str`
9999
"""
100100
return self._annotation
@@ -104,13 +104,19 @@ def parent_id(self) -> str:
104104
"""The files parent paste ID.
105105
106106
Returns
107-
--------
107+
-------
108108
:class:`str`
109109
"""
110110
return self._parent_id
111111

112112
@classmethod
113113
def from_data(cls, payload: FileResponse, /) -> Self:
114+
"""Method to create a File from an api response.
115+
116+
Returns
117+
-------
118+
:class:`~mystbin.File`
119+
"""
114120
self = cls(
115121
content=payload["content"],
116122
filename=payload["filename"],
@@ -123,14 +129,20 @@ def from_data(cls, payload: FileResponse, /) -> Self:
123129
return self
124130

125131
def to_dict(self) -> dict[str, Any]:
132+
"""Method to dump the File data to a serialized api payload.
133+
134+
Returns
135+
-------
136+
:class:`dict[:class:`str`, Any]`
137+
"""
126138
return {"content": self.content, "filename": self.filename}
127139

128140

129141
class Paste:
130142
"""Represents a Paste object from mystbin instances.
131143
132144
Attributes
133-
-----------
145+
----------
134146
id: :class:`str`
135147
The ID of this paste.
136148
created_at: :class:`datetime.datetime`
@@ -171,7 +183,7 @@ def url(self) -> str:
171183
"""The paste URL.
172184
173185
Returns
174-
--------
186+
-------
175187
:class:`str`
176188
"""
177189
return f"{self._http.root_url}{self.id}"
@@ -181,7 +193,7 @@ def expires(self) -> datetime.datetime | None:
181193
"""When the paste expires, if at all.
182194
183195
Returns
184-
--------
196+
-------
185197
Optional[:class:`datetime.datetime`]
186198
"""
187199
return self._expires
@@ -191,7 +203,7 @@ def views(self) -> int | None:
191203
"""The pastes view count, if any.
192204
193205
Returns
194-
--------
206+
-------
195207
Optional[:class:`int`]
196208
"""
197209
return self._views
@@ -201,13 +213,19 @@ def security_token(self) -> str | None:
201213
"""The pastes security token, if any.
202214
203215
Returns
204-
--------
216+
-------
205217
Optional[:class:`str`]
206218
"""
207219
return self._security
208220

209221
@classmethod
210222
def from_get(cls, payload: GetPasteResponse, /, *, http: HTTPClient) -> Self:
223+
"""Method to create a Paste from the api fetch response.
224+
225+
Returns
226+
-------
227+
:class:`~mystbin.Paste`
228+
"""
211229
files = [File.from_data(data) for data in payload["files"]]
212230
self = cls(
213231
http=http,
@@ -229,6 +247,12 @@ def from_get(cls, payload: GetPasteResponse, /, *, http: HTTPClient) -> Self:
229247

230248
@classmethod
231249
def from_create(cls, payload: CreatePasteResponse, files: Sequence[File], *, http: HTTPClient) -> Self:
250+
"""Method to create a Paste from the api response.
251+
252+
Returns
253+
-------
254+
:class:`~mystbin.Paste`
255+
"""
232256
self = cls(
233257
http=http,
234258
paste_id=payload["id"],
@@ -253,7 +277,7 @@ async def delete(self) -> None:
253277
This method will delete this paste from the mystbin instance.
254278
255279
Raises
256-
-------
280+
------
257281
ValueError
258282
The paste requires the security token to be present.
259283
"""

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ preview = true
7878
select = ["ALL"]
7979
ignore = [
8080
"ANN401",
81+
"COM812", # required for format
82+
"D105", # they don't need to be documented all the time
8183
"D400",
8284
"D401",
8385
"EM101", # in this case this is okay
@@ -92,6 +94,7 @@ ignore = [
9294
"Q000",
9395
"RUF001",
9496
"RUF009",
97+
"N818", # seems overeager
9598
"S101", # assert is used for type checking in this codebase
9699
"SIM105",
97100
"TRY003", # over-eager rule

0 commit comments

Comments
 (0)