Skip to content

Commit 04a5c22

Browse files
authored
Merge branch 'main' into schloerke/324-merge-api-and-resource
2 parents a1b4440 + 4051bfb commit 04a5c22

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/posit/connect/context.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from __future__ import annotations
2+
13
import functools
2-
from typing import Optional, Protocol
4+
from typing import TYPE_CHECKING, Protocol
35

4-
import requests
56
from packaging.version import Version
67

7-
from .urls import Url
8+
if TYPE_CHECKING:
9+
import requests
10+
11+
from .urls import Url
812

913

1014
def requires(version: str):
@@ -23,25 +27,24 @@ def wrapper(instance: ContextManager, *args, **kwargs):
2327
return decorator
2428

2529

26-
class Context(dict):
30+
class Context:
2731
def __init__(self, session: requests.Session, url: Url):
2832
self.session = session
2933
self.url = url
3034

3135
@property
32-
def version(self) -> Optional[str]:
33-
try:
34-
value = self["version"]
35-
except KeyError:
36+
def version(self) -> str | None:
37+
if not hasattr(self, "_version"):
3638
endpoint = self.url + "server_settings"
3739
response = self.session.get(endpoint)
3840
result = response.json()
39-
value = self["version"] = result.get("version")
40-
return value
41+
self._version: str | None = result.get("version")
42+
43+
return self._version
4144

4245
@version.setter
43-
def version(self, value):
44-
self["version"] = value
46+
def version(self, value: str | None):
47+
self._version = value
4548

4649

4750
class ContextManager(Protocol):

0 commit comments

Comments
 (0)