New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking subclass in to_source function #158
Comments
Hello, thank you for your report. |
Hello, Thanks for your quick reply. I followed the example from #113 and #114, and here is my source code import astor
import ast
from astor.string_repr import pretty_string
from astor.source_repr import pretty_source
class SubSourceGenerator(astor.code_gen.SourceGenerator):
def __init__(self, indent_with, add_line_information=False,
pretty_string=pretty_string,
# constants
len=len, isinstance=isinstance, callable=callable):
super().__init__(indent_with, add_line_information, pretty_string, len, isinstance, callable)
node = ast.parse('a=1')
astor.to_source(node, source_generator_class=SubSourceGenerator) Then I got:
Then I tried both issubclass(SubSourceGenerator, astor.code_gen.SourceGenerator)
>>> True
isinstance(SubSourceGenerator, astor.code_gen.SourceGenerator)
>>> False
isinstance(SubSourceGenerator(' '*4), astor.code_gen.SourceGenerator)
>>> True
isinstance(SubSourceGenerator(), astor.code_gen.SourceGenerator)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'indent_with' The Python version is 3.5.7. Thanks for your help and your amazing tool :). |
Ah, now I got your point! Thank you for the reproducer. That's definitely my mistake, sorry for the trouble. PR #151 should fix that faulty check. I'll try to get it merged this weekend. |
Yeah, PR #151 is the one I'd like to propose and fix. Thanks for checking that bug. |
Hello,
I have a question about the function
to_source()
incode_gen.py
. The reference is below:astor/astor/code_gen.py
Lines 54 to 59 in ef8a655
Since the message in line 57 mentions that line 56 means to check whether
source_generator_class
is the subclass ofastor.code_gen.SourceGenerator
or not, should line 56 usesissubclass(source_generator_class, astor.code_gen.SourceGenerator)
?Thanks for your answer.
The text was updated successfully, but these errors were encountered: