Skip to content

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 <[email protected]>
References:
* [AC-211] Add static type checking to CASE-Utilities-Python
* https://www.python.org/dev/peps/pep-0561/

Signed-off-by: Alex Nelson <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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.

3 participants