Skip to content

Commit

Permalink
Merge pull request #21 from alanisaac/cleanup-fixes
Browse files Browse the repository at this point in the history
Cleanup a variety of typing and duplicate errors
  • Loading branch information
alanisaac authored Apr 24, 2024
2 parents ae540a9 + 821d8c4 commit f9dad48
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ocsf_validator/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def __init__(
self.file = file
self.include = include
if isinstance(t, str):
self.cls = t
self.cls: str = t
else:
self.cls: str = t.__name__
self.cls = t.__name__
self.directive = directive
super().__init__(
f"`{directive}` type mismatch in {file}: expected type `{self.cls}` for {include}"
Expand Down
5 changes: 3 additions & 2 deletions ocsf_validator/matchers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
from abc import ABC
from pathlib import Path
from typing import Optional

Expand All @@ -11,7 +12,7 @@ def match(self, value: str) -> bool:
raise NotImplementedError()

@staticmethod
def make(pattern):
def make(pattern) -> Matcher:
if isinstance(pattern, Matcher):
return pattern
else:
Expand Down
4 changes: 2 additions & 2 deletions ocsf_validator/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ def apply(self, path: str) -> None:
class Dependencies:
"""A friendly list of dependencies."""

def __init__(self):
def __init__(self) -> None:
self._dependencies: dict[str, list[tuple[str, str]]] = {}

def add(self, child: str, parent: str, label: str = ""):
def add(self, child: str, parent: str, label: str = "") -> None:
if child not in self._dependencies:
self._dependencies[child] = []
self._dependencies[child].append((parent, label))
Expand Down
6 changes: 3 additions & 3 deletions ocsf_validator/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from enum import IntEnum
from pathlib import Path
from typing import Callable
from typing import Callable, Optional

from termcolor import colored

Expand Down Expand Up @@ -42,7 +42,7 @@ class ValidatorOptions:
base_path: str = "."
"""The base path of the schema."""

metaschema_path: str = None
metaschema_path: Optional[str] = None
"""The path to the schema's metaschema."""

extensions: bool = True
Expand Down Expand Up @@ -204,7 +204,7 @@ def txt_label(self, severity: int):
case _:
return self.txt_emphasize("???")

def validate(self):
def validate(self) -> None:
exit_code = 0
messages: dict[str, dict[int, set[str]]] = {}
collector = errors.Collector(throw=False)
Expand Down
2 changes: 1 addition & 1 deletion ocsf_validator/type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ocsf_validator.reader import Reader
from ocsf_validator.types import *

MATCHERS = [
MATCHERS: list = [
VersionMatcher(),
DictionaryMatcher(),
CategoriesMatcher(),
Expand Down
1 change: 0 additions & 1 deletion ocsf_validator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class OcsfInclude(TypedDict):


class OcsfProfile(TypedDict):
caption: str
caption: str
description: str
meta: str
Expand Down
2 changes: 1 addition & 1 deletion ocsf_validator/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def validate(reader: Reader, file: str):


def _default_get_registry(reader: Reader, base_uri: str) -> referencing.Registry:
registry = referencing.Registry()
registry: referencing.Registry = referencing.Registry()
for schema_file_path in reader.metaschema_path.glob("*.schema.json"):
with open(schema_file_path, "r") as file:
schema = json.load(file)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ocsf-validator"
version = "0.1.7"
version = "0.1.8"
description = "OCSF Schema Validation"
authors = [
"Jeremy Fisher <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_extends():
assert "thing" in r["/events/network/http_activity.json"]["attributes"]


def test_profiles():
def test_profiles_basic():
prof = event("profile1", ["thing"])
httpa = event("http_activity")
httpa["profiles"] = "profile1"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def test_validate_metaschemas():
}

def _get_registry(reader, base_uri) -> referencing.Registry:
registry = referencing.Registry()
registry: referencing.Registry = referencing.Registry()
for schema in METASCHEMA_MATCHERS.keys():
resource = referencing.Resource.from_contents(object_json_schema)
registry = registry.with_resource(base_uri + schema, resource=resource)
Expand Down

0 comments on commit f9dad48

Please sign in to comment.