Skip to content

Commit ada5f67

Browse files
committed
Fix invalid chars in Literal value
1 parent 72b0c20 commit ada5f67

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

json_to_models/dynamic_typing/complex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ def to_typing_code(self, types_style: Dict[Union['BaseType', Type['BaseType']],
265265
if options.get(self.TypeStyle.use_literals):
266266
limit = options.get(self.TypeStyle.max_literals)
267267
if limit is None or len(self.literals) < limit:
268-
parts = ', '.join(f'"{s}"' for s in sorted(self.literals))
268+
parts = ', '.join(
269+
'"{}"'.format(s.replace('\\', '\\\\').replace('"', '\\"'))
270+
for s in sorted(self.literals)
271+
)
269272
return [(Literal.__module__, 'Literal')], f"Literal[{parts}]"
270273

271274
return [], 'str'

test/test_cli/data/file.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ organization = Acme Widgets Inc.
66
; use IP address in case network name resolution is not working
77
server = 192.0.2.62
88
port = 143
9-
file = payroll.dat
9+
file = "payroll.dat"

0 commit comments

Comments
 (0)