Skip to content

Commit

Permalink
Add type signatures in support of strict type-review on example.py
Browse files Browse the repository at this point in the history
This patch does not take the last step of adding the `--strict` flag in
type review.

This patch satisfies a run of the type checker in strict mode against
the script `/example.py` and all of the library functions that script
depends on.  Additionally, all touched `__init__` methods observed to
not have `*args` & `**kwargs` catch-alls had those added and
incorporated into `super()` calls (which will assist with tying to,
e.g., knowledge base namespace helpers available in the ultimate parent
class `UcoThing`).

One effect reflected back into the example script is that the EXIF
dictionary incorporation logic needed its own keyword parameter, because
the `**kwargs` catch-all parameter being used was an atypical usage
versus the pass-through-to-superclass functionality of `**kwargs`.

This patch also adjusted one class position, moving `MessageThread`
under `ObservableObject` instead of `UcoObject`.  A follow-on patch will
do the same for `CaseInvestigation`.

Signed-off-by: Alex Nelson <[email protected]>
  • Loading branch information
ajnelson-nist committed Nov 27, 2024
1 parent 1331422 commit 33f0844
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 49 deletions.
8 changes: 4 additions & 4 deletions case_mapping/case/investigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(


class CaseInvestigation(UcoObject):
def __init__(self, name=None, focus=None, description=None, core_objects=None):
def __init__(
self, *args: Any, focus=None, core_objects=None, **kwargs: Any
) -> None:
"""
An investigative action is a CASE object that represents the who, where, when of investigation
:param name: The name of an investigation (e.g., Murder of Suspect B,.)
Expand All @@ -57,13 +59,11 @@ def __init__(self, name=None, focus=None, description=None, core_objects=None):
object e.g., Persons involved in investigation, Investigation into a Murder, object refrences a
case-object for a phone investigative action
"""
super().__init__()
super().__init__(*args, **kwargs)
self["@type"] = "case-investigation:Investigation"
self._str_vars(
**{
"uco-core:name": name,
"case-investigation:focus": focus,
"uco-core:description": description,
}
)
self.append_core_objects(core_objects)
Expand Down
8 changes: 6 additions & 2 deletions case_mapping/drafting/entities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from ..base import Facet, UcoObject, unpack_args_array


Expand Down Expand Up @@ -175,6 +177,7 @@ def __init__(
class SocialMediaActivityFacet(Facet):
def __init__(
self,
*args: Any,
body=None,
page_title=None,
author_identifier=None,
Expand All @@ -187,7 +190,8 @@ def __init__(
created_time=None,
application=None,
url=None,
):
**kwargs: Any,
) -> None:
"""
Used to represent activity on social platfomrs
:param body: The text of the post/message
Expand All @@ -203,7 +207,7 @@ def __init__(
:param application: the application used for creating the post
:param application: the URL of the post
"""
super().__init__()
super().__init__(*args, **kwargs)

self["@type"] = ["drafting:SocialMediaActivityFacet", "uco-core:Facet"]

Expand Down
12 changes: 7 additions & 5 deletions case_mapping/uco/identity.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Dict, Optional
from typing import Any, Dict, Optional

from ..base import Facet, IdentityAbstraction, UcoObject


class BirthInformationFacet(Facet):
def __init__(self, birthdate=None):
def __init__(self, *args: Any, birthdate=None, **kwargs: Any) -> None:
"""
:param birthdate: the date of birth of an identity
"""
super().__init__()
super().__init__(*args, **kwargs)
self["@type"] = "uco-identity:BirthInformationFacet"
self._datetime_vars(**{"uco-identity:birthdate": birthdate})

Expand All @@ -31,12 +31,14 @@ def __init__(self, name: Optional[str] = None, facets=None):


class SimpleNameFacet(Facet):
def __init__(self, given_name=None, family_name=None):
def __init__(
self, *args: Any, given_name=None, family_name=None, **kwargs: Any
) -> None:
"""
:param given_name: Full name of the identity of person
:param family_name: Family name of identity of person
"""
super().__init__()
super().__init__(*args, **kwargs)
self["@type"] = "uco-identity:SimpleNameFacet"
self._str_vars(
**{
Expand Down
7 changes: 3 additions & 4 deletions case_mapping/uco/location.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from typing import Optional
from typing import Any, Optional

from ..base import Facet, UcoObject


class Location(UcoObject):
def __init__(self, facets=None):
super().__init__()
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self["@type"] = "uco-location:Location"
self.append_facets(facets)


class LatLongCoordinatesFacet(Facet):
Expand Down
Loading

0 comments on commit 33f0844

Please sign in to comment.