summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Socol <me@jamessocol.com>2022-12-03 18:22:24 -0500
committerGitHub <noreply@github.com>2022-12-03 18:22:24 -0500
commit49091580be892254c43fe46cad0da673f07c3a5c (patch)
tree6d7784f4ec13616199f980b866a1c9e752da30f7
parentdc1cb87332c0233a1a280df37beee925f40d2f77 (diff)
parent50a9419794380bebc7d9ca51a06b3b8cb54e0e97 (diff)
downloadpystatsd-49091580be892254c43fe46cad0da673f07c3a5c.tar.gz
Merge pull request #176 from cclauss/pyupgrade_--py37-plus
pyupgrade: Modernize syntax for Python >= 3.7
-rw-r--r--docs/conf.py21
-rw-r--r--statsd/client/base.py10
-rw-r--r--statsd/client/timer.py2
-rw-r--r--statsd/client/udp.py4
-rw-r--r--statsd/tests.py6
5 files changed, 21 insertions, 22 deletions
diff --git a/docs/conf.py b/docs/conf.py
index 55aef11..e5141dd 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
# Python StatsD documentation build configuration file, created by
# sphinx-quickstart on Mon Apr 9 15:47:23 2012.
#
@@ -11,7 +9,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
+import os
+import sys
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
@@ -40,8 +39,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
-project = u'Python StatsD'
-copyright = u'2015, James Socol'
+project = 'Python StatsD'
+copyright = '2015, James Socol'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -183,8 +182,8 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'PythonStatsD.tex', u'Python StatsD Documentation',
- u'James Socol', 'manual'),
+ ('index', 'PythonStatsD.tex', 'Python StatsD Documentation',
+ 'James Socol', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -213,8 +212,8 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
- ('index', 'pythonstatsd', u'Python StatsD Documentation',
- [u'James Socol'], 1)
+ ('index', 'pythonstatsd', 'Python StatsD Documentation',
+ ['James Socol'], 1)
]
# If true, show URL addresses after external links.
@@ -227,8 +226,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- ('index', 'PythonStatsD', u'Python StatsD Documentation',
- u'James Socol', 'PythonStatsD', 'One line description of project.',
+ ('index', 'PythonStatsD', 'Python StatsD Documentation',
+ 'James Socol', 'PythonStatsD', 'One line description of project.',
'Miscellaneous'),
]
diff --git a/statsd/client/base.py b/statsd/client/base.py
index 61dcf18..4fbbe5c 100644
--- a/statsd/client/base.py
+++ b/statsd/client/base.py
@@ -5,7 +5,7 @@ from datetime import timedelta
from .timer import Timer
-class StatsClientBase(object):
+class StatsClientBase:
"""A Base class for various statsd clients."""
def close(self):
@@ -51,7 +51,7 @@ class StatsClientBase(object):
pipe._send_stat(stat, '%s|g' % value, 1)
else:
prefix = '+' if delta and value >= 0 else ''
- self._send_stat(stat, '%s%s|g' % (prefix, value), rate)
+ self._send_stat(stat, '{}{}|g'.format(prefix, value), rate)
def set(self, stat, value, rate=1):
"""Set a set value."""
@@ -64,12 +64,12 @@ class StatsClientBase(object):
if rate < 1:
if random.random() > rate:
return
- value = '%s|@%s' % (value, rate)
+ value = '{}|@{}'.format(value, rate)
if self._prefix:
- stat = '%s.%s' % (self._prefix, stat)
+ stat = '{}.{}'.format(self._prefix, stat)
- return '%s:%s' % (stat, value)
+ return '{}:{}'.format(stat, value)
def _after(self, data):
if data:
diff --git a/statsd/client/timer.py b/statsd/client/timer.py
index 453197e..5354a47 100644
--- a/statsd/client/timer.py
+++ b/statsd/client/timer.py
@@ -10,7 +10,7 @@ def safe_wraps(wrapper, *args, **kwargs):
return functools.wraps(wrapper, *args, **kwargs)
-class Timer(object):
+class Timer:
"""A context manager/decorator for statsd.timing()."""
def __init__(self, client, stat, rate=1):
diff --git a/statsd/client/udp.py b/statsd/client/udp.py
index 4e44d5c..ec10fc7 100644
--- a/statsd/client/udp.py
+++ b/statsd/client/udp.py
@@ -6,7 +6,7 @@ from .base import StatsClientBase, PipelineBase
class Pipeline(PipelineBase):
def __init__(self, client):
- super(Pipeline, self).__init__(client)
+ super().__init__(client)
self._maxudpsize = client._maxudpsize
def _send(self):
@@ -40,7 +40,7 @@ class StatsClient(StatsClientBase):
"""Send data to statsd."""
try:
self._sock.sendto(data.encode('ascii'), self._addr)
- except (socket.error, RuntimeError):
+ except (OSError, RuntimeError):
# No time for love, Dr. Jones!
pass
diff --git a/statsd/tests.py b/statsd/tests.py
index d1b2a96..5688977 100644
--- a/statsd/tests.py
+++ b/statsd/tests.py
@@ -69,7 +69,7 @@ def _timer_check(sock, count, proto, start, end):
send = send_method[proto](sock)
eq_(send.call_count, count)
value = send.call_args[0][0].decode('ascii')
- exp = re.compile(r'^%s:\d+|%s$' % (start, end))
+ exp = re.compile(r'^{}:\d+|{}$'.format(start, end))
assert exp.match(value)
@@ -85,7 +85,7 @@ def _sock_check(sock, count, proto, val=None, addr=None):
)
-class assert_raises(object):
+class assert_raises:
"""A context manager that asserts a given exception was raised.
>>> with assert_raises(TypeError):
@@ -132,7 +132,7 @@ class assert_raises(object):
def __exit__(self, typ, value, tb):
assert typ, 'No exception raised.'
- assert typ in self.exc_cls, '%s not in %s' % (
+ assert typ in self.exc_cls, '{} not in {}'.format(
typ.__name__, [e.__name__ for e in self.exc_cls])
self.exc_type = typ
self.exception = value