Skip to content

Commit

Permalink
Fix type hint on normalize prefix argument (#6008)
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca authored Mar 10, 2020
1 parent d5f02b5 commit 6b643db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,13 @@ def set_external_tags(self, external_tags):
raise

def convert_to_underscore_separated(self, name):
# type: (bytes) -> bytes
# type: (Union[str, bytes]) -> bytes
"""
Convert from CamelCase to camel_case
And substitute illegal metric characters
"""
metric_name = self.FIRST_CAP_RE.sub(br'\1_\2', ensure_bytes(name))
name = ensure_bytes(name)
metric_name = self.FIRST_CAP_RE.sub(br'\1_\2', name)
metric_name = self.ALL_CAP_RE.sub(br'\1_\2', metric_name).lower()
metric_name = self.METRIC_REPLACEMENT.sub(br'_', metric_name)
return self.DOT_UNDERSCORE_CLEANUP.sub(br'.', metric_name).strip(b'_')
Expand Down Expand Up @@ -693,7 +694,7 @@ def _format_namespace(self, s, raw=False):
return to_native_string(s)

def normalize(self, metric, prefix=None, fix_case=False):
# type: (Union[str, bytes], bytes, bool) -> str
# type: (Union[str, bytes], Union[str, bytes], bool) -> str
"""
Turn a metric into a well-formed metric name
prefix.b.c
Expand Down
4 changes: 3 additions & 1 deletion datadog_checks_base/datadog_checks/base/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import warnings
from decimal import ROUND_HALF_UP, Decimal
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Text, Union

from six import PY3, iteritems, text_type
from six.moves.urllib.parse import urlparse
Expand All @@ -16,12 +16,14 @@


def ensure_bytes(s):
# type: (Union[Text, bytes]) -> bytes
if isinstance(s, text_type):
s = s.encode('utf-8')
return s


def ensure_unicode(s):
# type: (Union[Text, bytes]) -> Text
if isinstance(s, bytes):
s = s.decode('utf-8')
return s
Expand Down

0 comments on commit 6b643db

Please sign in to comment.