Skip to content

Commit 3b63ea1

Browse files
committed
Replace typing.ContextManager with contextlib.AbstractContextManager
The former has been deprecated since Python 3.9.
1 parent 65e2dab commit 3b63ea1

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

langkit/compile_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
from __future__ import annotations
1313

1414
from collections import defaultdict
15-
from contextlib import contextmanager
15+
from contextlib import AbstractContextManager, contextmanager
1616
from enum import Enum
1717
from functools import reduce
1818
import importlib
1919
import os
2020
from os import path
21-
from typing import (Any, Callable, ContextManager, Dict, List, Optional, Set,
22-
TYPE_CHECKING, Tuple, Union, cast)
21+
from typing import (Any, Callable, Dict, List, Optional, Set, TYPE_CHECKING,
22+
Tuple, Union, cast)
2323

2424
from funcy import lzip
2525

@@ -852,7 +852,7 @@ def actual_version(self) -> str:
852852
def actual_build_date(self) -> str:
853853
return self.build_date or "undefined"
854854

855-
def lkt_context(self, lkt_node: L.LktNode) -> ContextManager[None]:
855+
def lkt_context(self, lkt_node: L.LktNode) -> AbstractContextManager[None]:
856856
"""
857857
Context manager to set the diagnostic context to the given node.
858858

langkit/compiled_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import annotations
22

33
from collections import OrderedDict
4+
from contextlib import AbstractContextManager
45
from dataclasses import dataclass
56
import difflib
67
from itertools import count, takewhile
78
import pipes
89
from typing import (
9-
Callable, ClassVar, ContextManager, Dict, Iterator, List, Optional as Opt,
10-
Sequence, Set, TYPE_CHECKING, Tuple, Union, ValuesView
10+
Callable, ClassVar, Dict, Iterator, List, Optional as Opt, Sequence, Set,
11+
TYPE_CHECKING, Tuple, Union, ValuesView
1112
)
1213

1314
from langkit import names
@@ -381,7 +382,7 @@ def uses_entity_info(self) -> bool:
381382
return self._uses_entity_info
382383

383384
@property
384-
def diagnostic_context(self) -> ContextManager[None]:
385+
def diagnostic_context(self) -> AbstractContextManager[None]:
385386
return diagnostic_context(self.location)
386387

387388
@property

langkit/dsl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3+
from contextlib import AbstractContextManager
34
import itertools
45
from typing import (
5-
Any, ContextManager, Dict, List, Optional as Opt, TYPE_CHECKING, Tuple,
6-
Type, Union
6+
Any, Dict, List, Optional as Opt, TYPE_CHECKING, Tuple, Type, Union
77
)
88

99
from langkit.compiled_types import (
@@ -49,7 +49,7 @@ def array(cls):
4949
'{}.array'.format(cls._name.camel))
5050

5151
@classmethod
52-
def _diagnostic_context(cls) -> ContextManager[None]:
52+
def _diagnostic_context(cls) -> AbstractContextManager[None]:
5353
return diagnostic_context(cls._location)
5454

5555
@staticmethod

langkit/envs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
from __future__ import annotations
1010

11+
from contextlib import AbstractContextManager
1112
from enum import Enum
1213
from funcy import lsplit_by
1314
from itertools import count
14-
from typing import ContextManager, Dict, List, Optional, Type, cast, overload
15+
from typing import Dict, List, Optional, Type, cast, overload
1516

1617
from langkit import names
1718
from langkit.compile_context import CompileCtx, get_context
@@ -252,7 +253,7 @@ def count(cls: Type[EnvAction], sequence: List[EnvAction]) -> int:
252253
self.actions = self.pre_actions + self.post_actions
253254

254255
@property
255-
def diagnostic_context(self) -> ContextManager[None]:
256+
def diagnostic_context(self) -> AbstractContextManager[None]:
256257
"""
257258
Diagnostic context for env specs.
258259
"""

langkit/expressions/structs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3+
from contextlib import AbstractContextManager
34
import inspect
4-
from typing import (Any as _Any, ContextManager, Dict, List, Optional,
5-
Sequence, Tuple)
5+
from typing import Any as _Any, Dict, List, Optional, Sequence, Tuple
66

77
import funcy
88

@@ -861,7 +861,7 @@ def __init__(self,
861861
self.node_data: AbstractNodeData
862862

863863
@property
864-
def diagnostic_context(self) -> ContextManager[None]:
864+
def diagnostic_context(self) -> AbstractContextManager[None]:
865865
return diagnostic_context(self.location)
866866

867867
def resolve_field(self) -> AbstractNodeData:

langkit/lexer/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
from collections import defaultdict
4+
from contextlib import AbstractContextManager
45
from itertools import count
56
import re
6-
from typing import (Any, ContextManager, Dict, Iterator, List, Optional,
7-
Sequence, Set, TYPE_CHECKING, Tuple, Type, Union, cast)
7+
from typing import (Any, Dict, Iterator, List, Optional, Sequence, Set,
8+
TYPE_CHECKING, Tuple, Type, Union, cast)
89

910
from langkit.compile_context import CompileCtx, get_context
1011
from langkit.diagnostics import (
@@ -321,7 +322,7 @@ def signature(self) -> tuple:
321322
sorted(t.signature for t in self.tokens))
322323

323324
@property
324-
def diagnostic_context(self) -> ContextManager[None]:
325+
def diagnostic_context(self) -> AbstractContextManager[None]:
325326
assert self.location is not None
326327
return diagnostic_context(self.location)
327328

langkit/parsers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
from __future__ import annotations
2424

2525
from collections import OrderedDict
26-
from contextlib import contextmanager
26+
from contextlib import AbstractContextManager, contextmanager
2727
import difflib
2828
from funcy import keep
2929
import inspect
3030
from itertools import count
3131
from typing import (
32-
Any, Callable, ContextManager, Dict, Iterator, List as _List, Optional,
33-
Sequence, Set, TYPE_CHECKING, Tuple, Type, Union
32+
Any, Callable, Dict, Iterator, List as _List, Optional, Sequence, Set,
33+
TYPE_CHECKING, Tuple, Type, Union
3434
)
3535

3636
import funcy
@@ -270,7 +270,7 @@ def __init__(self,
270270
If we loaded a Lkt unit, mapping of all grammar rules it contains.
271271
"""
272272

273-
def context(self) -> ContextManager[None]:
273+
def context(self) -> AbstractContextManager[None]:
274274
return diagnostic_context(self.location)
275275

276276
def _add_rule(self, name: str, parser: Parser, doc: str = "") -> None:
@@ -762,7 +762,7 @@ def set_location(self, location: Location) -> None:
762762
c.set_location(self.location)
763763

764764
@property
765-
def diagnostic_context(self) -> ContextManager[None]:
765+
def diagnostic_context(self) -> AbstractContextManager[None]:
766766
"""
767767
Helper that will return a diagnostic context manager with parameters
768768
set for the grammar definition.

0 commit comments

Comments
 (0)