Skip to content

Add typing to Worker module #37

@JuanTecedor

Description

@JuanTecedor

Currently, all cortexutils is missing typing, but we should start with the worker module as it is the root of the inheritance.

This makes writing analyzers with any static type checker very tedious.

One example of a noisy/hard function to type is any that uses error with conditional branching:

from cortexutils.analyzer import Analyzer

class ExampleAnalyzer(Analyzer):
    ...

    def preprocess_url(self, url: str) -> str:
        if not url.startswith("http"):
            self.error(f"Invalid URL: {url}")
        else:
            processed_url = url.lower()
            return processed_url
cortexutils/example.py:5: error: Missing return statement  [return]
Found 1 error in 1 file (checked 6 source files)

Current workaround is to add # type: ignore[return], which is not ideal as it invalidates most of the type safety.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions