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
Conversion failing with Python 3.9 #350
Comments
|
I'm ran into this today: maybe emitting a warning, when using python 3.9 that it is not usable yet (or fix the regression fast ;) ) |
|
Python slice ast has been changed: https://docs.python.org/3.9/library/ast.html#ast.AST
This means, that the AST has been changed: should be fairly easy to remove the |
|
I'm not entirely sure if this is correct for all cases, but it works for simple cases, e.g. the stopwatch in the cookbook: diff --git a/myhdl/conversion/_analyze.py b/myhdl/conversion/_analyze.py
index 9ad1111..9adcb08 100644
--- a/myhdl/conversion/_analyze.py
+++ b/myhdl/conversion/_analyze.py
@@ -976,7 +976,10 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin):
def accessIndex(self, node):
self.visit(node.value)
self.access = _access.INPUT
- self.visit(node.slice.value)
+ if hasattr(node.slice, 'value'):
+ self.visit(node.slice.value)
+ else:
+ self.visit(node.slice)
if isinstance(node.value.obj, _Ram):
if isinstance(node.ctx, ast.Store):
self.raiseError(node, _error.ListElementAssign)
diff --git a/myhdl/conversion/_toVHDL.py b/myhdl/conversion/_toVHDL.py
index 7942963..f2011b2 100644
--- a/myhdl/conversion/_toVHDL.py
+++ b/myhdl/conversion/_toVHDL.py
@@ -986,7 +986,8 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
rhs = node.value
# shortcut for expansion of ROM in case statement
if isinstance(node.value, ast.Subscript) and \
- isinstance(node.value.slice, ast.Index) and \
+ (isinstance(node.value.slice, ast.Index) or \
+ isinstance(node.value.slice, ast.Call)) and \
isinstance(node.value.value.obj, _Rom):
rom = node.value.value.obj.rom
self.write("case ")
@@ -2391,7 +2392,10 @@ class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin):
def accessIndex(self, node):
self.generic_visit(node)
node.vhd = vhd_std_logic() # XXX default
- node.slice.value.vhd = vhd_int()
+ if hasattr(node.slice, 'value'):
+ node.slice.value.vhd = vhd_int()
+ else:
+ node.slice.vhd = vhd_int()
obj = node.value.obj
if isinstance(obj, list):
assert len(obj)
diff --git a/myhdl/conversion/_toVerilog.py b/myhdl/conversion/_toVerilog.py
index 2f07fc8..060fb15 100644
--- a/myhdl/conversion/_toVerilog.py
+++ b/myhdl/conversion/_toVerilog.py
@@ -749,8 +749,10 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
def visit_Assign(self, node):
# shortcut for expansion of ROM in case statement
+ print(f"{type(node.value.slice)}")
if isinstance(node.value, ast.Subscript) and \
- isinstance(node.value.slice, ast.Index) and\
+ (isinstance(node.value.slice, ast.Index) or\
+ isinstance(node.value.slice, ast.Call)) and\
isinstance(node.value.value.obj, _Rom):
rom = node.value.value.obj.rom
# self.write("// synthesis parallel_case full_case") |
|
@hellow554 thanks for the information on the 3.9 changes. I know it has been awhile, we will try and review this as soon as possible. |
|
IMO Python version dependencies should be handled by checking the Python version rather than checking for the effect that an attribute is or isn't available. |
|
I agree. I think this should be done with a version check. Probably just define 2 versions of the same check function depending on the python version... |
|
We used to have a global variable PY2 in _compat.py, but as we now only support Python3 that has gone; I suggest we create a new one in __init__.py: (Uppercase because it is treated as a constant) |
|
This is built-in and easy: Actually the |
|
Maybe we could add a step which runs on older python versions which modifies the AST to what we expect it to look on 39: for example: This would allow us to keep the compatibility related stuff outside the main ast processing code and hopefully make it easier for us to maintain? |
|
I guess it is 'six of the one and half a dozen of the other' |
|
IMO The test You specify ast.Subscript; but shouldn't we rewrite all occurrences? |
correct. my rewriting example was adapted from https://greentreesnakes.readthedocs.io/en/latest/manipulating.html#modifying-the-tree and i neglected to remove the ast.Subscript part. |
It is not necessary for the Num/Constant case, but I think it would be needed for the slices case? |
You are quite right, the conversion of slices need the test. |
|
@josyb sounds good. gimme a day to review it. |
|
This looks fixed to me now. Can we close? |
Python 3.9 was added to the travis regression, majority of the regression tests failed:
https://travis-ci.org/github/myhdl/myhdl/jobs/747059472
System information
The text was updated successfully, but these errors were encountered: