Closed martinRenou closed 5 years ago
@martinRenou : it's the py3.4 and before behavior, so there is no way around: if you want to support these versions, you need to handle the case where True and False are not reserved names. And thanks to gast you can handle this in both codes. Considering the change, basically read gast README, each difference between gast and python ast (for each version) is emphasized there
btw a typical pattern is import gast as ast
@serge-sans-paille I am not sure I get it... According to the gast README:
In Python3, None, True and False are parsed as NamedConstant while they are parsed as regular Name in Python2. gast uses the same convention
I understand that gast
handle it automatically and turn False
, True
and None
into NamedConstant
, without having to make a workaround. Do I understand this wrong?
Ok yes, I see I understand it wrong now. This line is actually saying the behavior does not change for both Python2 and Python3, is that it?
Then I'm not sure we need gast in py2vega, because all the other use cases handled by gast will have no effect on py2vega. py2vega
does not allow functiondef
, classdef
, with
, raise
, tryexcept
or comprehension
.
Note: We might add list comprehension support at some point by unrolling it in the vega-expression. But for the other nodes I don't think we'll ever support them.
Maybe Python 3.8 support in gast will have an effect on py2vega?
Yes, bacause of the ast node ast.Constant that makes ast.Num obsoletes
Ok :) I'll add the gast
dependency for the Python 3.8 support then. Did you not consider having the same behavior for Python 2 and Python 3 concerning the NamedConstant
? Is it not possible?
It's not trivial:
from mymodule import *
print(True)
Is a valid Python2 input, and you cannot state if True
is a NamedConstant
or a
Name
, depending on the (unknown) content of mymodule
@serge-sans-paille it seems that I get
False
andTrue
asgast.Name
and notgast.NameConstant
in Python 2.7, because it triggers theNodeVisitor.visit_Name
method. Should I be doing something more than simply replacingast
bygast
in my code?