google/python-fire

Only plain literals should be parsed

Open

#97 ouverte le 12 oct. 2017

Voir sur GitHub
 (9 commentaires) (0 réactions) (0 assignés)Python (1 418 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (26 214 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

@dbieber correctly pointed out in #95 that there is a more general problem with the parsing code. This is a follow up issue to that issue which only dealt with the most common case of a single argument.

Here are some cases demonstrating

$ python3 -c "import fire.parser as p; v = p.DefaultParseValue('[1+1]'); print(type(v), v)"
<class 'list'> [2]
$ python3 -c "import fire.parser as p; v = p.DefaultParseValue('{key: 1+1}'); print(type(v), v)"
<class 'dict'> {'key': 2} 

Some options are:

  1. Accept the existing behaviour.
  2. Always parse the whole argument as a string by doing raise ValueError in ``fire.parser._LiteralEval`
  3. Parse only the sub expressions as strings

For 2. and 3. I think these would be the valid types from the ast module.

  • Str
  • Name (converted to Str)
  • Num
  • List
  • Tuple
  • Dict
  • Set
  • UnaryOp

Guide contributeur