-
Notifications
You must be signed in to change notification settings - Fork 31
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
Refactoring, type annotations and fixes #51
Conversation
…PDUs Instead of duplicating code already in the above two classes, existing classes that implement the same functionality use them instead. Access to the underlying attributes is provided through @property-decorated methods. Affected classes: Data Query PDU Action Request PDU Data PDU Set Data PDU Event Report PDU Comment PDU ... and their Reliable counterparts
Remove unnecessary whitespace, and add any where required to follow PEP8 recommendations.
…ically Instead of storing the number of fixed datums and variable datums as an attribute, calculate it from the list of fixed/variable datums when required. The original attribute names are still accessible, through class properties.
This style is no longer required in Python 3; all classes that do not inherit another superclass are automatically assumed to subclass object.
These are moved from the __init__() to class attributes. This pattern makes it less likely for users to accidentally initialise the class with the wrong recordType or recordLength, where these values are known beforehand. Class attributes are accessible by instances of the class, so the serialize() and parse() methods are unaffected. ### Further changes - added type annotations to attributes, marking them as being an enum, int, or float, along with their size in bits - fixed init types for some attributes - removed some unnecessary comments - added table UID in comments for some enums
These are calculated from the list of fixed/variable datum records instead. The attributes are still accessible as properties.
…xedDatum or VariableDatum
Changes: - removed redundant comments, whitespace - added type aliases for Python int, float, bytes - added type annotation for init parameters, padding - added UID number in comments for enums from SISO-REF-010 - changed superclass attribute values (pduType, protocolFamily) from init to class attributes - Fixed some parsing of arrays
While this pull request is open, another quick question. I found this in the codebase: open-dis-python/opendis/dis7.py Lines 273 to 286 in 76dedb4
This class appears to be unused. I have left it in the codebase for now. If it is also legacy code (in the same category as the *Chunk classes), let me know and I'll push another commit to remove it. |
The type aliases are moved to their own file, types.py, to avoid a dependency loop.
This is considered safer as it automatically releases the file handle if the program should crash before f.close() is reached.
Thank-you @ngjunsiang |
quick ping @leif81 to see if there's anything else you need to see for this PR? |
Have started to review, I should be able to finish up in next couple days. |
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.
@ngjunsiang the change is very large (>7000 lines changed), which makes it very difficult and time consuming to review. But I feel good about what I'm seeing. I will proceed with merging it. Thank-you for the improvement
This continues and extends the work initiated in open-dis#51
This fix work from open-dis#51 introduced in e9b6788 and regression from 98b2834
This pull request covers a number of changes:
Use DataQueryDatumSpecification and DatumSpecification in composition
This implements the change proposed in #49 (comment)
Before:
open-dis-python/opendis/dis7.py
Lines 6 to 22 in 3a52c4f
After:
open-dis-python/opendis/dis7.py
Lines 6 to 24 in b4ccb3d
Before:
open-dis-python/opendis/dis7.py
Lines 5042 to 5067 in 3a52c4f
After:
open-dis-python/opendis/dis7.py
Lines 4781 to 4815 in f62b7e3
Any fixes to DataQueryDatumSpecification and DatumSpecification will not need to be copied to the classes that use it.
Style fixes
object
which is a Python2 requirement; Python 3 no longer requires itBugfixes
Some parsing code I found to be non-compliant with IEEE 1278.1-2012 has been fixed. Also replaced a few null() calls with calls to the appropriate classes (addressing #14, but not yet completely fixed)
Add type annotations
This implements the change proposed in #49 (comment)
Type aliases
open-dis-python/opendis/dis7.py
Lines 5 to 19 in 76dedb4
The above type aliases are equivalent to the Python classes (int, float, bytes) assigned to them, and are used in type annotations to add more information about the required parameter type (enum, record (struct), signed or unsigned int, float) and size.
Type annotations have been added to most init parameters (some tricky ones are still unannotated), and it should be pretty clear from the annotations what is required now. In supported IDEs, these annotations can also be read and displayed in help text:
Future work
This is groundwork for future pull requests aimed at organising and structuring the codebase, so as to make it easier to address the open issues.
In particular, the current code structure and flow (instantiating a single PDU class to wrap an input/output stream for serialization/parsing) makes it tricky to handle bitfields and sub-enumerations. I'm working on a parallel effort, a code generator for enumerations from SISO-REF-010 which can be used with this package to provide introspection (auto-lookup of enum values) and unpack bitfields.