Skip to content

Commit

Permalink
Testing things with the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
fortwoone committed Nov 29, 2023
1 parent 5ac2989 commit 1bb54bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=too-many-instance-attributes,too-many-locals
pylint $(git ls-files '*.py') --disable=too-many-instance-attributes,too-many-locals --max-line-length=150
7 changes: 6 additions & 1 deletion pyzora/game_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
You should have received a copy of the GNU General Public
License along with pyzora. If not, see <https://www.gnu.org/licenses/>.
"""
from pyzora.secret import *
import copy as mod_copy
from pyzora.secret import (BaseSecret, parse_secret, Byte, calculate_checksum,
byte_array_to_string, string_to_byte_array, reverse_substring,
integer_string, reverse_string)
from pyzora.enums import (TargetGame, ObtainedCompanion, ChildBehaviour,
GameRegion)
from pyzora.exceptions import SecretError, ChecksumError, NotAGameCodeError


class GameSecret(BaseSecret):
Expand Down
7 changes: 6 additions & 1 deletion pyzora/memory_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
You should have received a copy of the GNU General Public
License along with pyzora. If not, see <https://www.gnu.org/licenses/>.
"""
from pyzora.secret import *
from pyzora.secret import (BaseSecret, parse_secret, byte_array_to_string,
string_to_byte_array, reverse_substring, integer_string,
calculate_checksum, reverse_string)
from pyzora.enums import MemoryEnum, GameRegion, TargetGame
from pyzora.exceptions import SecretError, ChecksumError, NotAMemoryCodeError


class MemorySecret(BaseSecret):
Expand Down Expand Up @@ -73,6 +77,7 @@ def __init__(self, *args, **kwargs):

@classmethod
def load(cls, secret: bytearray | bytes | str, region: GameRegion):
"""Load a memory secret from bytes or a string."""
if isinstance(secret, str):
# Secret string. Parse it before doing anything else.
# Allows the user to give the region only once
Expand Down
16 changes: 9 additions & 7 deletions pyzora/ring_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
You should have received a copy of the GNU General Public
License along with pyzora. If not, see <https://www.gnu.org/licenses/>.
"""
from pyzora.secret import *
from pyzora.ring_types import *
from pyzora.secret import (BaseSecret, parse_secret, byte_array_to_string,
calculate_checksum, reverse_string, integer_string,
reverse_substring, string_to_byte_array)
from pyzora.enums import GameRegion
from pyzora.exceptions import SecretError, ChecksumError, NotARingCodeError
from pyzora.ring_types import * # noqa


class RingSecret(BaseSecret):
Expand Down Expand Up @@ -73,10 +77,9 @@ def __init__(self, *args, **kwargs):
def __contains__(self, item):
if item is NoRings:
return not self.rings
elif item is AllRings:
if item is AllRings:
return self.rings == int(AllRings)
else:
return (item & self.rings) == item
return (item & self.rings) == item

@classmethod
def load(cls, secret: bytearray | bytes | str, region: GameRegion):
Expand All @@ -95,7 +98,7 @@ def load(cls, secret: bytearray | bytes | str, region: GameRegion):
if (decoded_bytes[14] & 0xF) != (checksum & 0xF):
raise ChecksumError(f"checksum {checksum} does not match expected value : {decoded_bytes[14]}")
if decoded_secret[3] != "0" or decoded_secret[4] != "1":
raise NotARingCodeError(f"given secret is not a ring code")
raise NotARingCodeError("given secret is not a ring code")
game_id = int(reverse_substring(decoded_secret, 5, 15))
ring_str = "".join((reverse_substring(decoded_secret, 36, 8),
reverse_substring(decoded_secret, 76, 8),
Expand Down Expand Up @@ -157,4 +160,3 @@ def to_list(self):

def __hash__(self):
return hash((self.__game_id, self.__rings))

0 comments on commit 1bb54bb

Please sign in to comment.