Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes code quality improvements to the files module, such as type hints and typo corrections.
Commit Details
1. fix: better type hint in EndianBinaryReader/Writer
In
EndianBinaryReader
, use-> Tuple[xxx, ...]
instead of-> Tuple[xxx]
, where the latter one is a common mistake.In
EndianBinaryWriter
, usevalue: Sequence
instead ofvalue: list
because some invocations pass a tuple argument instead of list.2. refactor(files): use assertion for version-specific assignment
Use
assert xxx is not None
before value assignment.This is also the practice adopted by
MeshHelper
and other classes, which can correctly satisfy the NoneType checking.3. chore(files): fix typo and remove legacy code
In
File
class:class File(object)
can be simplified toclass File
(Python 3).self.environment = self.environment = ...
causes a duplicated self-assignment.In
ContainerHelper
, method__or__
cannot be used anymore since 5ac0a62 changed the constructor of this class.4. fix(files): overall type hint corrections
Correct the type hints in the files module.
Refactors
BundleFile.get_version_tuple
:(next(...), next(...), next(...))
instead oftuple(map(...))
to respect the returned type-> Tuple[int, int, int]
.AttributeError
by validating the regex match before accessinggroups
.