Skip to content

Commit

Permalink
perf: use type instead of isinstance
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Aug 13, 2023
1 parent d00f602 commit eb48ceb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 4 additions & 6 deletions keywin/keyboard/utils/convert_to_key_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ def convert_to_key_code(string: str) -> list[list[int]]:
try:
key_codes: list[list[int]] = []

for key_with_modifier, group in groupby((Typables.table[character] for character in string), lambda x: isinstance(x, list)):
group_list = list(group)

if key_with_modifier:
key_codes.extend(group_list)
for key, group in groupby((Typables.table[character] for character in string), type):
if key == list:
key_codes.extend(group) # pyright: ignore[reportGeneralTypeIssues]

else:
key_codes.append(group_list)
key_codes.append(list(group)) # pyright: ignore[reportGeneralTypeIssues]

return key_codes

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ disable = [
"line-too-long",
"too-few-public-methods"
]

[tool.pyright]
typeCheckingMode = "strict"
reportUnknownVariableType = false
reportUnknownMemberType = false
reportMissingTypeStubs = false

0 comments on commit eb48ceb

Please sign in to comment.