Skip to content

Commit 1d12b8c

Browse files
committed
Fix parsing & dumping of compiled patterns in initialization options
cattrs appears not to have support for these types built-in, which is perhaps surprising, though happily fixable via its hooks.
1 parent 438b862 commit 1d12b8c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

jedi_language_server/initialization_options.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
initialization options.
55
"""
66

7+
import re
78
from dataclasses import dataclass, field, fields, is_dataclass
89
from typing import Any, List, Optional, Pattern, Set
910

@@ -149,3 +150,14 @@ def structure(cls: type) -> Any:
149150
initialization_options_converter.register_structure_hook_factory(
150151
is_dataclass, structure
151152
)
153+
154+
155+
initialization_options_converter.register_structure_hook_factory(
156+
lambda x: x == Pattern[str],
157+
lambda _: lambda x, _: re.compile(x),
158+
)
159+
160+
initialization_options_converter.register_unstructure_hook_factory(
161+
lambda x: x == Pattern[str],
162+
lambda _: lambda x: x.pattern,
163+
)

0 commit comments

Comments
 (0)