Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
go/ast: FilterFile filters out import declarations #9248
It seems that ast.FilterFile does not take ast.ImportSpecs into account when applying the filter function, leading to them being filtered out of the ast by default.
I suspect that add type case for ast.ImportSpec here:
would potentially solve this.
This behavior is exhibited in both 1.3 and 1.4rc1
I'm writing a code writing tool that uses AST analysis and transformation to produce specific implementations of generic algorithms on matching types. Part of this process is analyzing what imports from the 'type provider' file need to be added to the specific implementation of the generic code in order to be correct.
It honestly shouldn't be hard to roll my own, but ast.FilterFile at least presents itself as the canonical implementation of what I'm trying to do. It's ok if it can't change, but maybe the documentation should be updated to indicate the limitation if that's the case.
It may actually be easier to simply filter the imports yourself. I'd rather not change/add to this code at this point (the ast.FilterFile function is one of the very oldest pieces of library code and a new implementation would look rather different).
Let's leave the issue open so that we remember to document it eventually. Thanks.