Skip to content

Commit

Permalink
Add 3.10 Self fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed May 6, 2024
1 parent 77c9e72 commit 1ec15a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions tivars/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


from io import BytesIO
from typing import BinaryIO, Self, Type
from sys import version_info
from typing import BinaryIO, Type
from warnings import warn

from .data import *
Expand All @@ -13,6 +14,14 @@
from .numeric import BCD


match version_info[:2]:
case 3, 10:
Self = 'TIFlashHeader'

case _:
from typing import Self


class DeviceType(Enum):
"""
Enum of flash device types
Expand Down Expand Up @@ -547,7 +556,7 @@ def checksum(self) -> bytes:
return self.raw.checksum

@classmethod
def get_type(cls, type_id: int) -> Type['TIFlashHeader']:
def get_type(cls, type_id: int) -> Type['TIFlashHeader'] | None:
"""
Gets the subclass corresponding to a type ID if one is registered
Expand Down
13 changes: 11 additions & 2 deletions tivars/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@


from io import BytesIO
from typing import BinaryIO, Iterator, Self, Type
from sys import version_info
from typing import BinaryIO, Iterator, Type
from warnings import warn

from .data import *
from .models import *
from .tokenizer import TokenizedString


match version_info[:2]:
case 3, 10:
Self = 'TIEntry'

case _:
from typing import Self


class TIHeader:
"""
Parser for var file headers
Expand Down Expand Up @@ -552,7 +561,7 @@ def meta(self) -> bytes:
return self.raw.calc_data_length + self.raw.type_id + self.raw.name + self.raw.version + self.raw.archived

@classmethod
def get_type(cls, type_id: int) -> Type['TIEntry']:
def get_type(cls, type_id: int) -> Type['TIEntry'] | None:
"""
Gets the subclass corresponding to a type ID if one is registered
Expand Down

0 comments on commit 1ec15a6

Please sign in to comment.