Eliminate unnecessary cast() calls via improved type narrowing#454
Draft
Eliminate unnecessary cast() calls via improved type narrowing#454
cast() calls via improved type narrowing#454Conversation
- types.py: Use int() instead of cast(int, ...) for slice indices; improve isinstance-based type narrowing in startswith/endswith; remove redundant cast after isinstance in replace_placeholders; extract named function for snake_case; fix mutable default argument anti-pattern in escape() - collection.py: Remove cast after isinstance check in filter list - conditions.py: Remove self-cast in postprocess; remove unnecessary list cast in selector postprocess - backends/test/backend.py: Remove cast from finalize methods - conversion/base.py: Use list comprehension with isinstance for type narrowing; use typed local variables instead of untyped dict for expression backup; replace casts with isinstance-narrowed list in convert_condition_as_in_expression; add isinstance check in convert_condition_field_eq_expansion - rule/detection.py: Remove casts from to_plain dict merging; use assert for item_linking; use str() instead of cast for regex modifier - processing/pipeline.py: Remove casts for covariant Mapping/dict types - processing/transformations/values.py: Use isinstance filtering and assert for type narrowing - processing/resolver.py: Remove unused cast import Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/9d74a408-80b0-44ee-bd4a-bac479a824f8 Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Replace int() and str() with assert isinstance() for type narrowing in types.py, detection.py, and conversion/base.py to avoid changing runtime behavior while still properly narrowing types. Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/9d74a408-80b0-44ee-bd4a-bac479a824f8 Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
thomaspatzke
April 6, 2026 23:10
View session
…g-hints # Conflicts: # sigma/backends/test/backend.py # sigma/conditions.py # sigma/processing/pipeline.py # sigma/processing/resolver.py # sigma/rule/detection.py Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SigmaHQ/pySigma/sessions/5d39cfa1-24c2-4f63-9c5d-ff4bac00e054 Co-authored-by: thomaspatzke <1845601+thomaspatzke@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
list[SigmaType]type annotation to sigma_val variablefinalize_query_defaultcalls withstr()and fixtype: ignorecomment error codes