fix: guard against None import names causing AttributeError crashes#1291
Open
MorningStar0709 wants to merge 1 commit into
Open
fix: guard against None import names causing AttributeError crashes#1291MorningStar0709 wants to merge 1 commit into
MorningStar0709 wants to merge 1 commit into
Conversation
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
|
@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. |
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.
Summary
When
imp["name"]isNone(which can occur with certain relative/star/aliased import forms produced by tree-sitter parsers), calling.split()or.endswith()on it raisesAttributeError: 'NoneType' object has no attribute 'split', crashing indexing andcgc watch.Root Cause
Multiple locations across the codebase build
local_importsdictionaries 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 resolutioninheritance.py— inheritance links and decorator path resolutioncalls.py— function call groups (bothfile_local_importsand inline comprehension)Additionally,
_resolve_decorator_pathininheritance.pyaccesseslocal_imports[decorator_name]and calls.split()on the value without a None guard. Thebuild_decorated_by_linksandbuild_metaclass_linksfunctions constructlocal_importsusingimp.get("source"), but Python parser imports lack a"source"field — soimportedis alwaysNonefor Python decorators/metaclasses.Changes
graph_builder.pyif imp.get('name')guard +not imp['name'].endswith('.*')wildcard filter tolocal_importsinheritance.pyL91if imp.get("name")guard tolocal_importsdict comprehensioninheritance.pyL322_resolve_decorator_path: wrapimported.split()inif imported:block, fall through toimports_maplookupinheritance.pyL351, L407imp.get("source") or imp.get("full_import_name")as value inlocal_importsforbuild_decorated_by_linksandbuild_metaclass_links— this fixes decorator/metaclass resolution for Python (which hasfull_import_namebut notsource)calls.pyL1754imp.get("name") andtofile_local_importsfilter conditioncalls.pyL2145, L2152imp.get("name") andtolocal_importsandwildcard_importsfilter conditionselisp.pyL685and imp.get("name")guard toimports_mappre-scanTesting
python -m py_compilesyntax checksAttributeErrorcrashes on projects where parsers produceNoneimport namesfull_import_namefallback improves decorator/metaclass path resolution accuracy for Python projectsRelated Issues
cgc watchincremental indexing NoneType split crash