Skip to content
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

AST Parser Matching Name assignments should choose last match #246

Closed
techalchemy opened this issue May 28, 2020 · 0 comments · Fixed by #247
Closed

AST Parser Matching Name assignments should choose last match #246

techalchemy opened this issue May 28, 2020 · 0 comments · Fixed by #247
Labels
bug Something isn't working

Comments

@techalchemy
Copy link
Member

Currently, the setup.py AST parser will look for matches by name when matching assignments in setup.py. If a name has been assigned multiple times, however, the first assignment is chosen instead of the most recent assignment, which can cause major problems for the parser which will be working with an incomplete / unparsed object.

For example, when unparsing the following ast.BinOp instance:

	matches = entry['key'][0]['matches']
	matches = [x for x in matches if 'some_string' not in x]
	entry['key'][0]['matches'] = matches + other_list

the first assignment of matches is chosen, causing the following exception:

  File "<stdin>", line 1, in <module>
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1201, in ast_parse_setup_py
    ast_analyzer.unmap_binops()
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 729, in unmap_binops
    self.binOps_map[binop] = ast_unparse(binop, analyzer=self)
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1017, in ast_unparse
    left_item = unparse(item.left)
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1040, in ast_unparse
    items = unparse(analyzer.assignments[assignment])
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1140, in ast_unparse
    val = unparse(item.value, recurse=False)
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1000, in ast_unparse
    unparsed = unparse(item.value)
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1000, in ast_unparse
    unparsed = unparse(item.value)
  File "/home/techalchemy/git/requirementslib/src/requirementslib/models/setup_info.py", line 1004, in ast_unparse
    unparsed = unparsed[unparse(item.slice.value)]
TypeError: string indices must be integers

string indices must be integers
@techalchemy techalchemy added the bug Something isn't working label May 28, 2020
techalchemy added a commit that referenced this issue May 29, 2020
- Additionally fix handling of `os.environ` based version numbers and
  other assignments
- Fixes #246

Signed-off-by: Dan Ryan <dan.ryan@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant