Skip to content

Semver2 fix 656#681

Open
TheCommCraft wants to merge 3 commits into
semver2from
semver2_fix_656
Open

Semver2 fix 656#681
TheCommCraft wants to merge 3 commits into
semver2from
semver2_fix_656

Conversation

@TheCommCraft

Copy link
Copy Markdown
Collaborator

Solves issue #656

Changes

Add 1 to every packet number requested, change packet request detection

Tests

@faretek1 faretek1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some general comments about the code but there is nothing critically obvious to the logic to me. As long as you have tested it well, it is probably safe to commit


@property
def var_sets_since_first(self) -> int:
return self.var_stets_since_first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we cannot fix the typo itself (due to semver)

self.last_var_set = time.time()

def get_var(self, var, *, recorder_initial_values={}):
def get_var(self, var, *, recorder_initial_values: Optional[dict] = None):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want to replicate the original behaviour you need to check if recorder... is None: recorder... = {}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original behaviour was potentially dangerous due to a dangerous default

return self.recorder.get_var(var)

def get_all_vars(self, *, recorder_initial_values={}):
def get_all_vars(self, *, recorder_initial_values: Optional[dict] = None):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above for none check

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to just make it a required field instead of optional



class ScratchCloud(BaseCloud):
class ScratchCloud(LogCloud):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean all scratch clouds now print logs? Is this desired?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A log cloud is just a cloud that has a logs method


def __init__(self, request_name, *, on_call, cloud_requests, thread=True, enabled=True, response_priority=0, debug=False):
def __init__(
self,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat unrelated but a note that typing could be added here

def __init__(
self,
cloud,
used_cloud_vars=["1", "2", "3", "4", "5", "6", "7", "8", "9"],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old code was like this too but list literals shouldnt be used as default arguments

Comment thread scratchattach/eventhandlers/cloud_requests.py Outdated
Comment on lines +305 to +307
if len(request_id) == 7 and request_id[-1] == "9":
# A lost packet was re-requested
self._request_packet_from_memory(request_id[1:], int(raw_request))
self._request_packet_from_memory(request_id[:-1], int(raw_request) + 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this is the actual fix? Have you tested it? I presume so? The main thing to test is if it can handle large payloads. Does that work?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with the code and project from the issue that this fixes (with large payloads)

Comment thread scratchattach/eventhandlers/cloud_requests.py Outdated
Comment on lines +442 to +447
logs = getattr(self.cloud, "logs", None)
if logs is None:
return
extradata = logs(limit=35)[
::-1
] # Reverse result so oldest activity is first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also part of the core fix? In which cases would there not be a logs method? Is getattr really the best solution here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logs method exists for LogClouds (which a tw connection is not) and the original behaviour would be raising an AttributeError which would instantly get caught so this is actually equivalent

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i only added the getattr thingy to please ty/mypy

@TheCommCraft

Copy link
Copy Markdown
Collaborator Author

applied some of the requested changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants