Add types to validators, time, types

Update pyproject.toml to ignore boards, user_keymaps for mypy
Update pyproject.toml to reduce loud mypy reporting
This commit is contained in:
sofubi 2021-08-15 21:23:02 +00:00
parent 2c69d0e197
commit 75f9d10cc7
4 changed files with 19 additions and 11 deletions

View File

@ -7,7 +7,7 @@ from kmk.types import (
)
def key_seq_sleep_validator(ms):
def key_seq_sleep_validator(ms: float) -> KeySeqSleepMeta:
return KeySeqSleepMeta(ms)

View File

@ -1,23 +1,23 @@
import time
def sleep_ms(ms):
def sleep_ms(ms: float) -> None:
return time.sleep(ms / 1000)
def ticks_ms():
def ticks_ms() -> float:
'''Has .25s granularity, but is cheap'''
return time.monotonic() * 1000
def ticks_diff(new, old):
def ticks_diff(new: float, old: float) -> float:
return new - old
def accurate_ticks():
def accurate_ticks() -> int:
'''Is more expensive, but good for time critical things'''
return time.monotonic_ns()
def accurate_ticks_diff(new, old, ms):
def accurate_ticks_diff(new: float, old: float, ms: float) -> bool:
return bool(new - old < ms * 1000000)

View File

@ -1,6 +1,7 @@
from typing import List, Optional, Tuple
from kmk.consts import UnicodeMode
from kmk.keys import KeyAttrDict
from typing import List, Optional
class AttrDict(dict):
@ -23,8 +24,8 @@ class LayerKeyMeta:
class ModTapKeyMeta:
def __init__(self, kc: Optional[KeyAttrDict] = None, mods: Optional[List[KeyAttrDict]] = None):
self.mods: Optional[List[KeyAttrDict]] = mods
def __init__(self, kc: Optional[KeyAttrDict] = None, mods: Optional[List[KeyAttrDict]] = None) -> None:
self.mods: Optional[List[KeyAttrDict]] = mods
self.kc: Optional[KeyAttrDict] = kc
@ -44,5 +45,5 @@ class UnicodeModeKeyMeta:
class TapDanceKeyMeta:
def __init__(self, codes):
def __init__(self, codes: Tuple[KeyAttrDict, ...]):
self.codes = codes

View File

@ -28,7 +28,14 @@ include = ["kmk"]
exclude = [
"hardware",
".venv",
"user_keymaps"
"user_keymaps",
"boards"
]
reportMissingModuleSource = false
# reports missing typestubs allowing for a code action to
# create new library typestubs
reportMissingTypeStubs = true
[tool.mypy]
exclude = "boards/|user_keymaps/"
ignore_missing_imports = true