Skip to content

Commit

Permalink
Fix asttokens comma misannotation bug; bump v.0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lmmx committed Jan 2, 2020
1 parent 6e5db6e commit f77f760
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ the process.

# Changelog

- version 0.2.4:
- fix bug relating to asttokens misannotating comma tokens' type as 54 (`ERRORTOKEN`) rather than 53
(`OP`), by just checking for comma tokens of type 54 matching the string `','`, will inform asttokens devs
- version 0.2.2:
- fix bug where names assigned outside of definitions were causing errors
- version 0.2.1:
Expand Down
8 changes: 8 additions & 0 deletions mvdef/src/import_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def multilinify_import_stmt_str(import_stmt_str, indent_spaces=4, trailing_comma
al_endpos = al_n_tok.endpos
else:
comma_tok = tko.find_token(al_n_tok, tok_type=53, tok_str=",")
if comma_tok.type == 0:
# Due to an error in asttokens, sometimes tok_type is given as 54
# although this should be an error (the failure tok_type is 0)
comma_tok = tko.find_token(al_n_tok, tok_type=54, tok_str=",")
assert comma_tok.type > 0, f"Unable to find comma token"
al_endpos = comma_tok.endpos
else:
Expand All @@ -104,6 +108,10 @@ def multilinify_import_stmt_str(import_stmt_str, indent_spaces=4, trailing_comma
al_endpos = al_as_tok.endpos
else:
comma_tok = tko.find_token(al_as_tok, tok_type=53, tok_str=",")
if comma_tok.type == 0:
# Due to an error in asttokens, sometimes tok_type is given as 54
# although this should be an error (the failure tok_type is 0)
comma_tok = tko.find_token(al_n_tok, tok_type=54, tok_str=",")
assert comma_tok.type > 0, f"Unable to find comma token"
al_endpos = comma_tok.endpos
alias_chunk = import_stmt_str[al_startpos:al_endpos]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="mvdef",
version="0.2.3",
version="0.2.4",
author="Louis Maddox",
author_email="louismmx@gmail.com",
description="Package to move functions and their import statements between files",
Expand Down

0 comments on commit f77f760

Please sign in to comment.