Skip to content

Commit b356c75

Browse files
committed
suggested review changes
1 parent 7a66cb7 commit b356c75

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

discord/ui/file_upload.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class FileUpload:
2121
2222
Parameters
2323
----------
24-
custom_id: Optional[:class:`str`]
25-
The ID of the input text field that gets received during an interaction.
2624
label: :class:`str`
2725
The label for the file upload field.
2826
Must be 45 characters or fewer.
27+
custom_id: Optional[:class:`str`]
28+
The ID of the input text field that gets received during an interaction.
2929
description: Optional[:class:`str`]
3030
The description for the file upload field.
3131
Must be 100 characters or fewer.
@@ -58,8 +58,8 @@ class FileUpload:
5858
def __init__(
5959
self,
6060
*,
61-
custom_id: str | None = None,
6261
label: str,
62+
custom_id: str | None = None,
6363
min_values: int | None = None,
6464
max_values: int | None = None,
6565
required: bool | None = True,
@@ -76,7 +76,7 @@ def __init__(
7676
raise ValueError("min_values must be between 0 and 10")
7777
if max_values and (max_values < 1 or max_values > 10):
7878
raise ValueError("max_length must be between 1 and 10")
79-
if not isinstance(custom_id, str) and custom_id is not None:
79+
if custom_id is not None and not isinstance(custom_id, str):
8080
raise TypeError(
8181
f"expected custom_id to be str, not {custom_id.__class__.__name__}"
8282
)
@@ -92,8 +92,7 @@ def __init__(
9292
required=required,
9393
id=id,
9494
)
95-
self._interaction: Interaction | None = None
96-
self._values: list[str] | None = None
95+
self._attachments: list[Attachment] | None = None
9796
self.row = row
9897
self._rendered_row: int | None = None
9998

@@ -165,17 +164,7 @@ def required(self, value: bool | None):
165164
@property
166165
def values(self) -> list[Attachment] | None:
167166
"""The files that were uploaded to the field."""
168-
if self._interaction is None:
169-
return None
170-
attachments = []
171-
for attachment_id in self._values:
172-
attachment_data = self._interaction.data["resolved"]["attachments"][
173-
attachment_id
174-
]
175-
attachments.append(
176-
Attachment(state=self._interaction._state, data=attachment_data)
177-
)
178-
return attachments
167+
return self._attachments
179168

180169
@property
181170
def width(self) -> int:
@@ -185,8 +174,13 @@ def to_component_dict(self) -> FileUploadComponentPayload:
185174
return self._underlying.to_dict()
186175

187176
def refresh_from_modal(self, interaction: Interaction, data: dict) -> None:
188-
self._interaction = interaction
189-
self._values = data.get("values", [])
177+
values = data.get("values", [])
178+
self._attachments = [
179+
Attachment(
180+
state=interaction._state,
181+
data=interaction.data["resolved"]["attachments"][attachment_id]
182+
) for attachment_id in values
183+
]
190184

191185
@staticmethod
192186
def uses_label() -> bool:

0 commit comments

Comments
 (0)