-
Notifications
You must be signed in to change notification settings - Fork 32
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
Enhancements for introspection and debugging #49
Conversation
## Testing ## This is a preview of a proposed change to the __init__() of classes in dis.py. Currently it is difficult to create an instance of the classes with predecided values, as their __init__() takes no arguments. I propose to set object attributes from params in the __init__(), with default values.
The proposal makes sense to me @ngjunsiang . I'll leave the PR open for a week to collect any other feedback . If there are no concerns raised as a comment here I'll go ahead and merge. |
Merge upstream
ignore .local and hidden files
Allow instantiating classes through their __init__() with desired attribute values
While this PR is still open, I have a couple of questions from going through the code in more detail as I add the init parameters: open-dis-python/opendis/dis7.py Lines 654 to 665 in 71c34b0
I see a few *Chunk classes in dis7.py but don't see them being used anywhere. What are these used for? open-dis-python/opendis/dis7.py Lines 329 to 346 in 71c34b0
I see in many classes that the padding is stored as an object attribute, although its value is always 0. This seems unnecessary when the padding can be added during serialization and ignored during parsing; is there a reason the padding value is kept? |
@ngjunsiang the OneByteChunk was intended to be refactored out, but some occurences may have been missed. A pull request to remove any remaining is welcome. |
@ngjunsiang About the padding, I don't know why it's like that, it's likely a relic of the old code generator. (Strike)Feel free to refactor that out too in a pull request.(/strike) |
@ngjunsiang I remember now about the padding. It's there to be explicit and consistent with the spec. It's a field of particular size. Suggest we leave the padding as is. |
Add __init__() parameters that enable instantiation of classes using Class() syntax in Python.
Removed the 1-byte, 2-byte, 4-byte, and 8-byte chunk classes
|
Further proposed changesI have a few other edits I'd like to make separately, after this merge, since they might change the implementation somewhat (even if I try to preserve the existing interface): Use composition for
|
Problem
While trying to test this package, I found that it was tedious to initialise classes from
dis7
as the__init__()
takes no arguments. That means PDUs and other objects must be instantiated first, then their attributes set one by one (or parsed from a stream).I also saw the same complaint in #12 and thought this might be a useful enhancement.
Solution
A typical design for data classes is for the attribute values to be taken from the
__init__()
parameters, so that objects can be initialised in one line. This can be implemented without breaking any of the tests or existing code, by giving the parameters default values.This PR shows the proposed change on three classes: DataQueryDatumSpecification, FixedDatum, and VariableDatum. I'd like to gauge interest (and any objections) in this feature first before I proceed to apply the same pattern to the remaining classes.
After PR