Skip to content

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

Merged
merged 8 commits into from
Oct 8, 2021
Merged

AC-211 #16

merged 8 commits into from
Oct 8, 2021

Conversation

ajnelson-nist
Copy link
Member

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

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants