Skip to content

Syntax Error in generated code #277

Closed
@phiresky

Description

@phiresky
  • cattrs version: current master
  • Python version: 3.10
  • Operating System: Linux

The error

 File ".venv/lib/python3.10/site-packages/cattrs/dispatch.py", line 122, in dispatch                                                
   return handler(typ)                                                                                                                                       
 File ".venv/lib/python3.10/site-packages/cattrs/converters.py", line 829, in gen_structure_mapping                                      
   h = make_mapping_structure_fn(                                                                                                                                         
 File ".venv/lib/python3.10/site-packages/cattrs/gen.py", line 726, in make_mapping_structure_fn
   eval(compile(script, "", "exec"), globs)                                                                                                                                
 File "<string>", line 17                                                                                                                                                 
   raise IterableValidationError('While structuring dict[typing.Union[typing.Literal['ca', 'pro', 'fa', 'car', 'ing_emb'], typing.Literal['wgr', 'cwg', 'fcc', 'wcc']], statistics.FrequenciesInfo]', errors, __cattr_mapping_cl)

    | SyntaxError: invalid syntax. Perhaps you forgot a comma?                                                                                                                 

The offending code is here gen :

image

It seems to generate code that assumes that the repr of the offending type does not include '. ' is not escaped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions