classy-python/ccbv

Replace `inspect` module for parsing

meshy opened this issue · 3 comments

meshy commented

We currently use the inspect module to extract Django code and structure.

This has several drawbacks:

  • The version of Django that we're parsing needs to be installed in the project (at least locally).
  • The inspect module executes code (on import) when parsing modules. This means:
    • We can only inspect code we trust.
    • Python code inspected can mutate itself on import (see #181 (comment) and #184 )

We recently refactored the populate_cbv script to abstract the importer into a protocol that will (hopefully) make it easier for new importers to be written. LibCSV may be an appropriate alternative to inspect.

class CodeImporter(Protocol):
def generate_code_data(self) -> Iterator[CodeElement]:
...

meshy commented

Python's ast module has potential, if we can be sure it preserves formatting.