Skip to content

fix: guard against None import names causing AttributeError crashes#1291

Open
MorningStar0709 wants to merge 1 commit into
CodeGraphContext:mainfrom
MorningStar0709:fix/none-guard-import-name-split
Open

fix: guard against None import names causing AttributeError crashes#1291
MorningStar0709 wants to merge 1 commit into
CodeGraphContext:mainfrom
MorningStar0709:fix/none-guard-import-name-split

Conversation

@MorningStar0709

Copy link
Copy Markdown
Contributor

Summary

When imp["name"] is None (which can occur with certain relative/star/aliased import forms produced by tree-sitter parsers), calling .split() or .endswith() on it raises AttributeError: 'NoneType' object has no attribute 'split', crashing indexing and cgc watch.

Root Cause

Multiple locations across the codebase build local_imports dictionaries using dict comprehensions like:

{imp.get("alias") or imp["name"].split(".")[-1]: imp["name"] for imp in file_data.get("imports", [])}

When an import entry has "name": None, the .split() call crashes. This affects:

  • graph_builder.py — function call resolution
  • inheritance.py — inheritance links and decorator path resolution
  • calls.py — function call groups (both file_local_imports and inline comprehension)

Additionally, _resolve_decorator_path in inheritance.py accesses local_imports[decorator_name] and calls .split() on the value without a None guard. The build_decorated_by_links and build_metaclass_links functions construct local_imports using imp.get("source"), but Python parser imports lack a "source" field — so imported is always None for Python decorators/metaclasses.

Changes

File Change
graph_builder.py Add if imp.get('name') guard + not imp['name'].endswith('.*') wildcard filter to local_imports
inheritance.py L91 Add if imp.get("name") guard to local_imports dict comprehension
inheritance.py L322 Guard _resolve_decorator_path: wrap imported.split() in if imported: block, fall through to imports_map lookup
inheritance.py L351, L407 Use imp.get("source") or imp.get("full_import_name") as value in local_imports for build_decorated_by_links and build_metaclass_links — this fixes decorator/metaclass resolution for Python (which has full_import_name but not source)
calls.py L1754 Add imp.get("name") and to file_local_imports filter condition
calls.py L2145, L2152 Add imp.get("name") and to local_imports and wildcard_imports filter conditions
elisp.py L685 Add defensive and imp.get("name") guard to imports_map pre-scan

Testing

  • All 4 modified files pass python -m py_compile syntax checks
  • The fix prevents AttributeError crashes on projects where parsers produce None import names
  • The full_import_name fallback improves decorator/metaclass path resolution accuracy for Python projects

Related Issues

When imp["name"] is None (e.g. certain relative/star/aliased import
forms), calling .split() or .endswith() on it raises AttributeError,
crashing indexing and cgc watch.

Changes:
- graph_builder.py: add None guard + wildcard filter to local_imports
- inheritance.py: add None guard to local_imports dict comprehension
- inheritance.py: guard _resolve_decorator_path against None imported
  values, fall through to global imports_map lookup
- inheritance.py: use full_import_name as fallback for decorator/meta-
  class resolution in build_decorated_by_links and build_metaclass_links
- calls.py: add None guards to file_local_imports and local_imports/
  wildcard_imports dict comprehensions
- elisp.py: add defensive None guard to imports_map pre-scan

Fixes CodeGraphContext#1272, fixes CodeGraphContext#1285
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@MorningStar0709 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog tasks

1 participant