-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APProcedurePatch: hotfix changing class variables to instance variables #2996
Changes from 2 commits
25e5e68
8620572
f4ac421
be970d8
59fca0b
b15ecd5
0cbc81f
e32bcb1
3de7b88
3bd2373
ef5318e
3a90dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,7 @@ class APProcedurePatch(APAutoPatchInterface): | |
hash: Optional[str] # base checksum of source file | ||
source_data: bytes | ||
patch_file_ending: str = "" | ||
files: Dict[str, bytes] = {} | ||
files: Dict[str, bytes] | ||
|
||
@classmethod | ||
def get_source_data(cls) -> bytes: | ||
|
@@ -206,6 +206,7 @@ def get_source_data_with_cache(cls) -> bytes: | |
|
||
def __init__(self, *args: Any, **kwargs: Any): | ||
super(APProcedurePatch, self).__init__(*args, **kwargs) | ||
self.files = {} | ||
|
||
def get_manifest(self) -> Dict[str, Any]: | ||
manifest = super(APProcedurePatch, self).get_manifest() | ||
|
@@ -301,7 +302,7 @@ class APTokenMixin: | |
bytes, # WRITE | ||
Tuple[int, int], # COPY, RLE | ||
int # AND_8, OR_8, XOR_8 | ||
]]] = [] | ||
]]] | ||
|
||
def get_token_binary(self) -> bytes: | ||
""" | ||
|
@@ -355,6 +356,8 @@ def write_token(self, token_type: APTokenTypes, offset: int, data: Union[bytes, | |
""" | ||
Stores a token to be used by patching. | ||
""" | ||
if not getattr(self, "tokens", None): | ||
self.tokens = list() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whu not in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand it well, but I was guessing it had something to do with I don't understand the intended usage of this class that well though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least in my test using the KDL3 branch, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this could be a safer way: tokens: Sequence[
Tuple[APTokenTypes, int, Union[
bytes, # WRITE
Tuple[int, int], # COPY, RLE
int # AND_8, OR_8, XOR_8
]]] = () def write_token(self, token_type: APTokenTypes, offset: int, data: Union[bytes, Tuple[int, int], int]):
"""
Stores a token to be used by patching.
"""
if not isinstance(self.tokens, list):
self.tokens = []
self.tokens.append((token_type, offset, data)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe safer still: if not isinstance(self.tokens, list):
assert len(self.tokens) == 0, f"some funny business happened with {type(self)}.tokens"
self.tokens = [] In case someone makes an assignment without ...also maybe renaming it to
Silvris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.tokens.append((token_type, offset, data)) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I completely forgot about hasattr.
Your
getattr(...)
would returnFalse
fortokens = []
whilehasattr(...)
would returnTrue
. Not sure which is better.getattr
could hide mistakes whilehasattr
is more likely in accidental sharing of class vars again. I feel likehasattr
would be expected here though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree I think. I mostly used
getattr
because I forgothasattr
existed.