Skip to content

Commit

Permalink
Remove workaround for typeshed issue 7724
Browse files Browse the repository at this point in the history
Even though the issue is still open, the workaround is apparently not
needed anymore.

python/typeshed#7724

Change-Id: Ia5ead6c7ac3a667655b8eb70860920d37ecd9423
  • Loading branch information
jherbel committed Sep 8, 2023
1 parent e8444fa commit 451b82a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 64 deletions.
5 changes: 1 addition & 4 deletions cmk/notification_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import cmk.utils.paths
from cmk.utils.escaping import escape, escape_permissive
from cmk.utils.http_proxy_config import deserialize_http_proxy_config
from cmk.utils.misc import typeshed_issue_7724
from cmk.utils.notify import find_wato_folder, NotificationContext
from cmk.utils.notify_types import PluginNotificationContext

Expand Down Expand Up @@ -255,9 +254,7 @@ def post_request(
response = requests.post( # nosec B113
url=url,
json=message_constructor(context),
proxies=typeshed_issue_7724(
deserialize_http_proxy_config(serialized_proxy_config).to_requests_proxies()
),
proxies=deserialize_http_proxy_config(serialized_proxy_config).to_requests_proxies(),
headers=headers,
verify=verify,
)
Expand Down
5 changes: 2 additions & 3 deletions cmk/special_agents/agent_datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from cmk.utils import paths, store
from cmk.utils.http_proxy_config import deserialize_http_proxy_config
from cmk.utils.misc import typeshed_issue_7724

from cmk.ec.export import ( # pylint: disable=cmk-module-layer-violation
SyslogForwarderUnixSocket,
Expand Down Expand Up @@ -253,7 +252,7 @@ def get_request(
f"{self._api_url}/{version}/{api_endpoint}",
headers=self._query_heads,
params=params,
proxies=typeshed_issue_7724(self._proxy.to_requests_proxies()),
proxies=self._proxy.to_requests_proxies(),
)

def post_request(
Expand All @@ -266,7 +265,7 @@ def post_request(
f"{self._api_url}/{version}/{api_endpoint}",
headers=self._query_heads,
json=body,
proxies=typeshed_issue_7724(self._proxy.to_requests_proxies()),
proxies=self._proxy.to_requests_proxies(),
)


Expand Down
4 changes: 1 addition & 3 deletions cmk/special_agents/agent_fritzbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

import requests

from cmk.utils.misc import typeshed_issue_7724

from cmk.special_agents.utils import vcrtrace

UPNPInfo = tuple[Mapping[str, str], str, str]
Expand Down Expand Up @@ -131,7 +129,7 @@ def post(self, url: str, data: str, headers: Mapping[str, str]) -> requests.Resp
return self._session.post(
f"{self._urls[self._urlidx]}{url}",
data=data,
headers=typeshed_issue_7724(headers),
headers=headers,
timeout=self._timeout,
)

Expand Down
3 changes: 1 addition & 2 deletions cmk/special_agents/agent_mobileiron.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import requests

from cmk.utils.http_proxy_config import deserialize_http_proxy_config
from cmk.utils.misc import typeshed_issue_7724
from cmk.utils.regex import regex, REGEX_HOST_NAME_CHARS

from cmk.special_agents.utils.agent_common import (
Expand Down Expand Up @@ -146,7 +145,7 @@ def __init__(
self._devices_per_request = 200
self.regex_patterns = regex_patterns
self._proxy = deserialize_http_proxy_config(proxy)
if _requests_proxy := typeshed_issue_7724(self._proxy.to_requests_proxies()):
if _requests_proxy := self._proxy.to_requests_proxies():
self._session.proxies = _requests_proxy

def __enter__(self) -> MobileironAPI:
Expand Down
9 changes: 4 additions & 5 deletions cmk/utils/http_proxy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


from collections.abc import Mapping
from collections.abc import Mapping, MutableMapping
from typing import Protocol


class HTTPProxyConfig(Protocol):
def to_requests_proxies(self) -> Mapping[str, str] | None:
def to_requests_proxies(self) -> MutableMapping[str, str] | None:
...

def serialize(self) -> str:
Expand All @@ -36,7 +35,7 @@ def __eq__(self, o: object) -> bool:
class NoProxyConfig:
SERIALIZED = "NO_PROXY"

def to_requests_proxies(self) -> Mapping[str, str]:
def to_requests_proxies(self) -> dict[str, str]:
return {
"http": "",
"https": "",
Expand All @@ -53,7 +52,7 @@ class ExplicitProxyConfig:
def __init__(self, url: str) -> None:
self._url = url

def to_requests_proxies(self) -> Mapping[str, str]:
def to_requests_proxies(self) -> dict[str, str]:
return {
"http": self._url,
"https": self._url,
Expand Down
8 changes: 1 addition & 7 deletions cmk/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import itertools
import sys
import time
from collections.abc import Callable, Iterator, Mapping, MutableMapping
from collections.abc import Callable, Iterator
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -94,9 +94,3 @@ def cachefile_age(path: Path | str) -> float:
path = Path(path)

return time.time() - path.stat().st_mtime


def typeshed_issue_7724(x: Mapping[str, str] | None) -> MutableMapping[str, str] | None:
"""Temporary workaround for https://github.com/python/typeshed/issues/7724
TODO: Remove this when the issue a above is fixed!"""
return None if x is None else dict(x)
Loading

0 comments on commit 451b82a

Please sign in to comment.