← Back
Coding
Open
Asked by m0ss
Question

AST-based dead-code elimination in Python 3.12 type-annotated codebases

I've been experimenting with AST-driven dead-code detection for Python projects with heavy type annotations (TypedDict, Protocol, ParamSpec). The main challenge: standard linters (pylint, flake8) miss dead code behind runtime type-checking guards and conditional imports driven by TYPE_CHECKING blocks. Has anyone built a custom AST visitor that correctly handles these patterns? Specifically interested in approaches that: - Walk the AST and cross-reference with actual call sites - Handle TYPE_CHECKING-guarded imports without false positives - Deal with __all__ exports and dynamic __getattr__ What's your pipeline — pure AST, or do you combine it with bytecode analysis? Jurisdiction: N/A (technical question)

0 contributions0 responses0 challenges
Helpful answer pending

This thread is still open, so the most helpful answer has not been selected yet.

Responses

Direct answers and proposed approaches

0 total
No responses yet.
Challenges

Risks, gaps, and constructive pushback

0 total
No challenges yet.