Skip to content

Modernize type hints and dispatchers for Python 3.10+#451

Merged
thomaspatzke merged 7 commits intomainfrom
copilot/enhance-code-readability
Apr 6, 2026
Merged

Modernize type hints and dispatchers for Python 3.10+#451
thomaspatzke merged 7 commits intomainfrom
copilot/enhance-code-readability

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

Since pySigma requires Python 3.10+, modernize the codebase to use contemporary syntax that was previously unavailable.

Type annotations → PEP 604 union syntax

  • Union[X, Y]X | Y (~170 occurrences)
  • Optional[X]X | None (~156 occurrences)
  • Dict, List, Set, Patterndict, list, set, re.Pattern
  • Removed now-unused typing imports
# Before
def foo(val: Optional[Union[str, int]] = None) -> Union[str, None]:
# After
def foo(val: str | int | None = None) -> str | None:

Condition dispatchers → match/case

Converted the three isinstance dispatch chains in conversion/base.py (convert_condition_field_eq_val, convert_condition_val, convert_condition) to structural pattern matching.

# Before
if isinstance(cond.value, SigmaCasedString):
    return self.convert_condition_field_eq_val_str_case_sensitive(cond, state)
elif isinstance(cond.value, SigmaString):
    ...

# After
match cond.value:
    case SigmaCasedString():
        return self.convert_condition_field_eq_val_str_case_sensitive(cond, state)
    case SigmaString():
        ...

Runtime type inspection compatibility

X | Y produces types.UnionType at runtime, not typing.Union. Updated the two places that inspect types at runtime:

  • modifiers.py: type_check() now handles both Union and UnionType
  • transformations/base.py: Switched from __annotations__ to get_type_hints() (required with from __future__ import annotations) and added UnionType handling

Copilot AI and others added 6 commits April 5, 2026 22:06
…ll source files

Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/a1b7f6ab-a5e7-4231-8851-52b5b2ecd426

Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
…lace isinstance tuple patterns with union syntax

Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/a1b7f6ab-a5e7-4231-8851-52b5b2ecd426

Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/a1b7f6ab-a5e7-4231-8851-52b5b2ecd426

Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
… mangled comment in detection.py

Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/a1b7f6ab-a5e7-4231-8851-52b5b2ecd426

Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
@thomaspatzke thomaspatzke marked this pull request as ready for review April 6, 2026 22:49
@thomaspatzke thomaspatzke merged commit f49862d into main Apr 6, 2026
20 checks passed
@thomaspatzke thomaspatzke deleted the copilot/enhance-code-readability branch April 6, 2026 22:49
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