Skip to content

Commit 252deaa

Browse files
committed
Add some typings into SDK
1 parent 0ca9890 commit 252deaa

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

splunklib/binding.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
3434
from contextlib import contextmanager
3535
from datetime import datetime
3636
from functools import wraps
37-
from io import BytesIO
38-
from urllib import parse
3937
from http import client
4038
from http.cookies import SimpleCookie
39+
from io import BytesIO
40+
from urllib import parse
4141
from xml.etree.ElementTree import XML, ParseError
42-
from .data import record
43-
from . import __version__
4442

43+
from splunklib.data import Record
44+
45+
from . import __version__
46+
from .data import record
4547

4648
logger = logging.getLogger(__name__)
4749

@@ -511,7 +513,7 @@ class Context:
511513
:param headers: List of extra HTTP headers to send (optional).
512514
:type headers: ``list`` of 2-tuples.
513515
:param retries: Number of retries for each HTTP connection (optional, the default is 0).
514-
NOTE: THIS MAY INCREASE THE NUMBER OF ROUNDTRIP CONNECTIONS
516+
NOTE: THIS MAY INCREASE THE NUMBER OF ROUNDTRIP CONNECTIONS
515517
TO THE SPLUNK SERVER AND BLOCK THE CURRENT THREAD WHILE RETRYING.
516518
:type retries: ``int``
517519
:param retryDelay: How long to wait between connection attempts if `retries` > 0 (optional, defaults to 10s).
@@ -653,7 +655,9 @@ def connect(self):
653655

654656
@_authentication
655657
@_log_duration
656-
def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
658+
def delete(
659+
self, path_segment, owner=None, app=None, sharing=None, **query
660+
) -> Record:
657661
"""Performs a DELETE operation at the REST path segment with the given
658662
namespace and query.
659663
@@ -716,7 +720,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
716720
@_log_duration
717721
def get(
718722
self, path_segment, owner=None, app=None, headers=None, sharing=None, **query
719-
):
723+
) -> Record:
720724
"""Performs a GET operation from the REST path segment with the given
721725
namespace and query.
722726
@@ -783,7 +787,7 @@ def get(
783787
@_log_duration
784788
def post(
785789
self, path_segment, owner=None, app=None, sharing=None, headers=None, **query
786-
):
790+
) -> Record:
787791
"""Performs a POST operation from the REST path segment with the given
788792
namespace and query.
789793
@@ -1357,7 +1361,7 @@ def get(self, url, headers=None, **kwargs):
13571361
url = url + UrlEncoded("?" + _encode(**kwargs), skip_encode=True)
13581362
return self.request(url, {"method": "GET", "headers": headers})
13591363

1360-
def post(self, url, headers=None, **kwargs):
1364+
def post(self, url, headers=None, **kwargs) -> Record:
13611365
"""Sends a POST request to a URL.
13621366
13631367
:param url: The URL.

splunklib/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"""
6060

6161
import contextlib
62-
import datetime
6362
import json
6463
import logging
6564
import re
@@ -68,8 +67,9 @@
6867
from time import sleep
6968
from urllib import parse
7069

70+
from splunklib.data import Record
71+
7172
from . import data
72-
from .data import record
7373
from .binding import (
7474
AuthenticationError,
7575
Context,
@@ -80,6 +80,7 @@
8080
_NoAuthenticationToken,
8181
namespace,
8282
)
83+
from .data import record
8384

8485
logger = logging.getLogger(__name__)
8586

@@ -808,7 +809,7 @@ class Endpoint:
808809
:class:`Entity` (essentially HTTP GET and POST methods).
809810
"""
810811

811-
def __init__(self, service, path):
812+
def __init__(self, service: Service, path):
812813
self.service = service
813814
self.path = path
814815

@@ -833,7 +834,9 @@ def get_api_version(self, path):
833834

834835
return api_version
835836

836-
def get(self, path_segment="", owner=None, app=None, sharing=None, **query):
837+
def get(
838+
self, path_segment="", owner=None, app=None, sharing=None, **query
839+
) -> Record:
837840
"""Performs a GET operation on the path segment relative to this endpoint.
838841
839842
This method is named to match the HTTP method. This method makes at least
@@ -916,7 +919,9 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query):
916919

917920
return self.service.get(path, owner=owner, app=app, sharing=sharing, **query)
918921

919-
def post(self, path_segment="", owner=None, app=None, sharing=None, **query):
922+
def post(
923+
self, path_segment="", owner=None, app=None, sharing=None, **query
924+
) -> Record:
920925
"""Performs a POST operation on the path segment relative to this endpoint.
921926
922927
This method is named to match the HTTP method. This method makes at least

splunklib/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
format, which is the format used by most of the REST API.
1717
"""
1818

19+
from typing import Any
1920
from xml.etree.ElementTree import XML
2021

2122
__all__ = ["load", "record"]
@@ -201,7 +202,7 @@ def load_value(element, nametable=None):
201202

202203

203204
# A generic utility that enables "dot" access to dicts
204-
class Record(dict):
205+
class Record(dict[Any, Any]): # pyright: ignore[reportExplicitAny]
205206
"""This generic utility class enables dot access to members of a Python
206207
dictionary.
207208

0 commit comments

Comments
 (0)