Skip to content

Commit

Permalink
More type fixes (#550)
Browse files Browse the repository at this point in the history
* Make sure more function args have types
* Use Optional where imported for consistency
* If an optional type, check if not None

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb committed Aug 4, 2024
1 parent eb0165b commit c4b8c64
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions precli/core/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
self._value_str = utils.to_str(value) if self._is_str else None

@staticmethod
def _get_func_ident(node: Node) -> Node | None:
def _get_func_ident(node: Node) -> Optional[Node]:
if node is None:
return None
# TODO(ericwb): does this function fail with nested calls?
Expand All @@ -41,7 +41,7 @@ def node(self) -> Node:
return self._node

@property
def identifier_node(self) -> Node | None:
def identifier_node(self) -> Optional[Node]:
"""
The node representing just the identifier of the argument.
Expand Down Expand Up @@ -82,6 +82,6 @@ def value(self):
return self._value

@property
def value_str(self) -> str | None:
def value_str(self) -> Optional[str]:
"""The value as a true string."""
return self._value_str
2 changes: 1 addition & 1 deletion precli/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def enabled(self) -> bool:
return self._enabled

@enabled.setter
def enabled(self, enabled):
def enabled(self, enabled: bool):
"""Set whether the rule is enabled"""
self._enabled = enabled

Expand Down
4 changes: 2 additions & 2 deletions precli/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def parse_file(
Result(
f"{parser.rule_prefix()}000" if parser else "NO_RULE",
location=Location(
start_line=e.lineno,
end_line=e.lineno,
start_line=e.lineno if e.lineno else 0,
end_line=e.lineno if e.lineno else 0,
),
artifact=artifact,
level=Level.ERROR,
Expand Down
4 changes: 2 additions & 2 deletions precli/core/symtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class SymbolTable:
def __init__(self, name, parent=None):
def __init__(self, name: str, parent=None):
self._name = name
self._parent = parent
self._symbols = {}
Expand Down Expand Up @@ -46,7 +46,7 @@ def __str__(self) -> str:


class Symbol:
def __init__(self, name, type, value):
def __init__(self, name: str, type: str, value: str):
self._name = name
self._type = type
self._value = value
Expand Down

0 comments on commit c4b8c64

Please sign in to comment.