Closed greenmonn closed 4 years ago
You can subclass astor.astor.SourceGenerator
, implement visit_
methods for those nodes, and then pass it as source_generator_class=YourCustomGenerator
to astor.to_source()
. Would that cover your use case?
currently, version 0.8, there is a minor bug in to_source()
that gets in a way:
if source_generator_class is None:
source_generator_class = SourceGenerator
elif not isinstance(source_generator_class, SourceGenerator):
raise TypeError('source_generator_class should be a subclass of SourceGenerator')
The isinstance() should have been issubclass()
@jeybrahms thanks for the report! It has been fixed in https://github.com/berkerpeksag/astor/commit/51c9e70f1b3a8877cb531ab9c5b1a814eefe7532.
@greenmonn please reopen if using my suggestion wouldn't solve your problem.
Hi, I'm using astor for manipulating AST nodes from target source file.
When I try to call
astor.to_source
with only the AST node of compare operator, such as GtE, Gt, LtE, Lt, etc, I faced to the errorNo defined handler for node of type GtE (or others)
.I'm wondered if you have any plan to support these types of nodes.
Thank you! #