forked from usnistgov/CASE-Utilities-Python
-
Notifications
You must be signed in to change notification settings - Fork 3
AC-211 #16
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch is to show what is needed to add static type checking with `mypy`. The brunt of the effort is adding `#type: ignore` annotations to `rdflib`. These can be removed once an `rdflib` release with the merged PR 1407 is issued. The additional package in `tests/requirements.txt` pertaining to `dateutil` was reported by `mypy`. DISCLAIMER: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-211] Add static type checking to CASE-Utilities-Python * RDFLib/rdflib#1407 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
References: * [AC-211] Add static type checking to CASE-Utilities-Python * https://www.python.org/dev/peps/pep-0561/ Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
An observed behavior is that mypy will not type signature analysis until one is added in the call path, e.g. designating `def main() -> None`. This patch is the minimal set of effects of adding a None return type to unit test functions. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
An observed behavior is that mypy will not type signature analysis until one is added in the call path, e.g. designating `def main() -> None`. This patch is the minimal set of effects of adding a None return type to unit test functions. No further changes needed. One test not committed is that, before this patch, this line could be put into a function (I chose the SPARQL selector's main()) without mypy complaining: x : str = 1 After requiring that function return a type, mypy appropriately raised an error. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Some further signature work will come to case_file. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
After adding a type signature to create_file_node(), mypy complained that _logger was undefined. That was correct, as I'd copied and pasted that section from DFXML's walk_to_dfxml.py. Another issue around a multi-value-types dictionary will require a bigger patch before the type signature gets committed. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
This uses an alternative light-class definition style more focused on type signatures. The example origin is cited inline. References: * [AC-211] Add static type checking to CASE-Utilities-Python Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
One more `# type: ignore` was added while awaiting rdflib PR #1407. These were all identified by adding the `--strict` flag to mypy for a run. I will leave it up for future discussion whether to use that flag, especially to wait for PR 1407 and to see if too much work would be induced versus runtime safety improvements. References: * [AC-211] Add static type checking to CASE-Utilities-Python * RDFLib/rdflib#1407 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
DISCLAIMER:
Participation by NIST in the creation of the documentation of mentioned
software is not intended to imply a recommendation or endorsement by the
National Institute of Standards and Technology, nor is it intended to
imply that any specific software is necessarily the best available for
the purpose.
References: