Skip to content

Commit ea6fbe0

Browse files
Source code is checked with ruff (#17)
* Tests are checked with ruff * Src is checked with ruff * [CI] A stage "Lint with ruff" is added
1 parent e70bd8d commit ea6fbe0

15 files changed

Lines changed: 87 additions & 84 deletions

File tree

.github/workflows/package-verification.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ jobs:
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install flake8 flake8-pyproject
30+
python -m pip install flake8 flake8-pyproject ruff
3131
- name: Lint with flake8
3232
run: |
3333
flake8 .
34+
- name: Lint with ruff
35+
run: |
36+
ruff check .
3437
3538
test:
3639
runs-on: ubuntu-latest

src/core/bugcheck_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def UnexpectedSituation(bugcheckSrc: str, bugcheckPoint: str, explain: str):
195195
bugcheckSrc, bugcheckPoint
196196
)
197197

198-
if not (explain is None) and explain != "":
198+
if explain is not None and explain != "":
199199
errMsg += " "
200200
errMsg += explain
201201

src/core/controller_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def Helper__InsertFileIntoIndex(
545545
assert fileKey != ""
546546
assert fileData.IsAlive()
547547

548-
if not (fileKey in filesByStrKeyDictionary.keys()):
548+
if fileKey not in filesByStrKeyDictionary.keys():
549549
filesByStrKeyDictionary[fileKey] = fileData
550550
else:
551551
indexItemData = filesByStrKeyDictionary[fileKey]
@@ -574,7 +574,7 @@ def Helper__DeleteFileIntoIndex(
574574
assert fileKey != ""
575575
assert fileData.IsAlive()
576576

577-
if not (fileKey in filesByStrKeyDictionary.keys()):
577+
if fileKey not in filesByStrKeyDictionary.keys():
578578
BugCheckError.FileIsNotFoundInIndex(fileKey, fileData.m_Path)
579579

580580
indexItemData = filesByStrKeyDictionary[fileKey]
@@ -586,14 +586,14 @@ def Helper__DeleteFileIntoIndex(
586586
if typeOfIndexItemData == fileData:
587587
assert indexItemData is fileData
588588

589-
if not (indexItemData is fileData):
589+
if indexItemData is not fileData:
590590
BugCheckError.FileIsNotFoundInIndex(fileKey, fileData.m_Path)
591591

592592
filesByStrKeyDictionary.pop(fileKey)
593-
assert not (fileKey in filesByStrKeyDictionary.keys())
593+
assert fileKey not in filesByStrKeyDictionary.keys()
594594
return
595595

596-
if typeOfIndexItemData == list:
596+
if typeOfIndexItemData is list:
597597
assert type(indexItemData) is list
598598
assert len(indexItemData) > 1
599599

@@ -635,7 +635,7 @@ def Helper__InsertOptionIntoIndex(
635635
assert type(optionsByNameDictionary) is dict
636636
assert type(optionData) is PgCfgModel__OptionData
637637

638-
if not (optionData.m_Name in optionsByNameDictionary.keys()):
638+
if optionData.m_Name not in optionsByNameDictionary.keys():
639639
optionsByNameDictionary[optionData.m_Name] = optionData
640640
return
641641

@@ -666,7 +666,7 @@ def Helper__DeleteOptionFromIndex(
666666
assert type(optionsByNameDictionary) is dict
667667
assert type(optionData) is PgCfgModel__OptionData
668668

669-
if not (optionData.m_Name in optionsByNameDictionary.keys()):
669+
if optionData.m_Name not in optionsByNameDictionary.keys():
670670
BugCheckError.OptionIsNotFoundInIndex(optionData.m_Name)
671671

672672
data = optionsByNameDictionary[optionData.m_Name]
@@ -675,17 +675,17 @@ def Helper__DeleteOptionFromIndex(
675675

676676
typeOfData = type(data)
677677

678-
if typeOfData == PgCfgModel__OptionData:
678+
if typeOfData is PgCfgModel__OptionData:
679679
assert data is optionData
680680

681-
if not (data is optionData):
681+
if data is not optionData:
682682
BugCheckError.OptionIsNotFoundInIndex(optionData.m_Name)
683683

684684
optionsByNameDictionary.pop(optionData.m_Name)
685-
assert not (optionData.m_Name in optionsByNameDictionary.keys())
685+
assert optionData.m_Name not in optionsByNameDictionary.keys()
686686
return
687687

688-
if typeOfData == list:
688+
if typeOfData is list:
689689
assert type(data) is list
690690
assert len(data) > 1
691691

src/core/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def ExtractFirstOptionFromIndexItem(
3333

3434
typeOfIndexItem = type(indexItem)
3535

36-
if typeOfIndexItem == OptionData:
36+
if typeOfIndexItem is OptionData:
3737
assert indexItem.m_Name == optionName
3838
return indexItem
3939

40-
if typeOfIndexItem == list:
40+
if typeOfIndexItem is list:
4141
assert len(indexItem) > 1
4242
assert indexItem[0] is not None
4343
assert type(indexItem[0]) is OptionData

src/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__int.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def PrepareSetValue(self, ctx: OptionHandlerCtxToPrepareSetValue) -> any:
2626

2727
typeOfOptionValue = type(ctx.OptionValue)
2828

29-
if typeOfOptionValue == int:
29+
if typeOfOptionValue is int:
3030
return ctx.OptionValue
3131

3232
optionName = ctx.OptionName
3333
assert type(optionName) is str
3434

35-
if typeOfOptionValue == str:
35+
if typeOfOptionValue is str:
3636
if not str(ctx.OptionValue).isnumeric():
3737
RaiseError.CantConvertOptionValue(optionName, typeOfOptionValue, int)
3838

src/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__str.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def PrepareSetValue(self, ctx: OptionHandlerCtxToPrepareSetValue) -> any:
2626

2727
typeOfOptionValue = type(ctx.OptionValue)
2828

29-
if typeOfOptionValue != str:
29+
if typeOfOptionValue is not str:
3030
optionName = ctx.OptionName
3131
assert type(optionName) is str
3232
RaiseError.BadOptionValueType(optionName, typeOfOptionValue, str)

src/core/option/handlers/prepare_set_value/option_handler_to_prepare_set_value__std__unique_str_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def PrepareSetValue(self, ctx: OptionHandlerCtxToPrepareSetValue) -> any:
3232

3333
typeOfOptionValue = type(ctx.OptionValue)
3434

35-
if typeOfOptionValue == str:
35+
if typeOfOptionValue is str:
3636
result = ReadUtils.Unpack_StrList2(ctx.OptionValue)
3737
assert result is not None
3838
assert type(result) is list
3939
return result
40-
elif typeOfOptionValue == list:
40+
elif typeOfOptionValue is list:
4141
result: typing.List[str] = list()
4242
index: typing.Set[str] = set()
4343

src/core/option/handlers/prepare_set_value_item/option_handler_to_prepare_set_value_item__std__str.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def PrepareSetValueItem(self, ctx: OptionHandlerCtxToPrepareSetValueItem) -> any
2626

2727
typeOfOptionValue = type(ctx.OptionValueItem)
2828

29-
if typeOfOptionValue != str:
29+
if typeOfOptionValue is not str:
3030
optionName = ctx.OptionName
3131
assert type(optionName) is str
3232
RaiseError.BadOptionValueItemType(optionName, typeOfOptionValue, str)

src/core/option/handlers/write/option_handler_to_write__std__generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def OptionValueToString(self, ctx: OptionHandlerCtxToWrite) -> str:
3636

3737
typeOfOptionValue = type(ctx.OptionValue)
3838

39-
if typeOfOptionValue == int:
39+
if typeOfOptionValue is int:
4040
return __class__.sm_Handler_For_Int.OptionValueToString(ctx)
4141

42-
if typeOfOptionValue == str:
42+
if typeOfOptionValue is str:
4343
return __class__.sm_Handler_For_Str.OptionValueToString(ctx)
4444

45-
if typeOfOptionValue == bool:
45+
if typeOfOptionValue is bool:
4646
return __class__.sm_Handler_For_Bool.OptionValueToString(ctx)
4747

4848
BugCheckError.UnknownOptionValueType(ctx.OptionName, typeOfOptionValue)

0 commit comments

Comments
 (0)