Skip to content

Commit 3ce4b4d

Browse files
yezz123aminalaee
andauthored
chore: Improve Code Style (#15)
Co-authored-by: Amin Alaee <[email protected]>
1 parent 2f5319a commit 3ce4b4d

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.codecov.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
comment: off
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 1%
7+
8+
comment: false

sqladmin/fields.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def _get_object_list(self) -> List[tuple]:
341341
if self._object_list is None:
342342
query = self.query if self.query is not None else self.query_factory()
343343
get_pk = self.get_pk
344-
self._object_list = list((str(get_pk(obj)), obj) for obj in query)
344+
self._object_list = [(str(get_pk(obj)), obj) for obj in query]
345345
return self._object_list
346346

347347
def iter_choices(self) -> Generator[Tuple[str, str, bool], None, None]:
@@ -434,7 +434,7 @@ def pre_validate(self, form: Form) -> None:
434434
if self._invalid_formdata:
435435
raise ValidationError(self.gettext("Not a valid choice"))
436436
elif self.data:
437-
obj_list = list(x[1] for x in self._get_object_list())
437+
obj_list = [x[1] for x in self._get_object_list()]
438438
for v in self.data:
439439
if v not in obj_list:
440440
raise ValidationError(self.gettext("Not a valid choice"))

sqladmin/models.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ModelAdminMeta(type):
4848
def __new__(mcls, name, bases, attrs: dict, **kwargs: Any):
4949
cls: Type["ModelAdmin"] = super().__new__(mcls, name, bases, attrs)
5050

51-
model = kwargs.get("model", None)
51+
model = kwargs.get("model")
5252

5353
if not model:
5454
return cls
@@ -68,7 +68,7 @@ def __new__(mcls, name, bases, attrs: dict, **kwargs: Any):
6868

6969
cls.name = attrs.get("name", prettify_class_name(cls.model.__name__))
7070
cls.name_plural = attrs.get("name_plural", f"{cls.name}s")
71-
cls.icon = attrs.get("icon", None)
71+
cls.icon = attrs.get("icon")
7272

7373
mcls._check_conflicting_options(["column_list", "column_exclude_list"], attrs)
7474
mcls._check_conflicting_options(
@@ -249,11 +249,10 @@ def get_details_columns(cls) -> List[Tuple[str, Column]]:
249249

250250
@classmethod
251251
def get_column_labels(cls) -> Dict[Column, str]:
252-
column_labels = {}
253-
for column_label, value in cls.column_labels.items():
254-
column_labels[cls.get_column_by_attr(column_label)] = value
255-
256-
return column_labels
252+
return {
253+
cls.get_column_by_attr(column_label): value
254+
for column_label, value in cls.column_labels.items()
255+
}
257256

258257
@classmethod
259258
async def delete_model(cls, obj: str) -> None:

0 commit comments

Comments
 (0)