Skip to content

Commit 18ba348

Browse files
authored
Enable ruff built in linter rules (#1356)
* Enable ruff linter * Fix RUF010 explicit-f-string-type-conversion * Fix RUF021 parenthesize-chained-operators * Fix RUF005 collection-literal-concatenation * Fix RUF022 unsorted-dunder-all * Remove incorrect type annotations from tests * Fix RUF034 useless-if-else * Disable 1 instance of RUF006 asyncio-dangling-task * Fix RUF015 unnecessary-iterable-allocation-for-first-element * Fix RUF012 mutable-class-default * Ignore unicode characters in LLM responses * Permanently disable flake8-self linter * Ruff format * Fix new issues * Remove unused noqa directive
1 parent 5661e81 commit 18ba348

File tree

96 files changed

+227
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+227
-219
lines changed

.github/workflows/get-envs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main(f):
2626
joined_envs = ",".join(filtered_envs)
2727

2828
assert joined_envs, ( # noqa: S101
29-
f"No environments found.\nenvironments = {str(environments)}\nGROUP_NUMBER = {GROUP_NUMBER + 1}\nTOTAL_GROUPS = {TOTAL_GROUPS}"
29+
f"No environments found.\nenvironments = {environments!s}\nGROUP_NUMBER = {GROUP_NUMBER + 1}\nTOTAL_GROUPS = {TOTAL_GROUPS}"
3030
)
3131
print(joined_envs)
3232

newrelic/api/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
class Application:
2424
_lock = threading.Lock()
25-
_instances = {}
25+
_instances = {} # noqa: RUF012
2626

27-
_delayed_callables = {}
27+
_delayed_callables = {} # noqa: RUF012
2828

2929
@staticmethod
3030
def _instance(name, activate=True):

newrelic/api/html_insertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def insert_at_index(index):
7878
xua_meta = _xua_meta_re.search(data)
7979
charset_meta = _charset_meta_re.search(data)
8080

81-
index = max(xua_meta and xua_meta.end() or 0, charset_meta and charset_meta.end() or 0)
81+
index = max((xua_meta and xua_meta.end()) or 0, (charset_meta and charset_meta.end()) or 0)
8282

8383
if index:
8484
return insert_at_index(index)

newrelic/api/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def format(self, record):
131131

132132

133133
class NewRelicLogForwardingHandler(logging.Handler):
134-
IGNORED_LOG_RECORD_KEYS = {"message", "msg"}
134+
IGNORED_LOG_RECORD_KEYS = frozenset(("message", "msg"))
135135

136136
def emit(self, record):
137137
try:

newrelic/api/time_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
436436
_, error_group_name = process_user_attribute("error.group.name", error_group_name_raw)
437437
if error_group_name is None or not isinstance(error_group_name, str):
438438
raise ValueError(
439-
f"Invalid attribute value for error.group.name. Expected string, got: {repr(error_group_name_raw)}"
439+
f"Invalid attribute value for error.group.name. Expected string, got: {error_group_name_raw!r}"
440440
)
441441
except Exception:
442442
_logger.error(

newrelic/common/agent_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def __init__(
283283
else:
284284
self._host = proxy.host
285285
self._port = proxy.port or 443
286-
self._prefix = f"{self.PREFIX_SCHEME + host}:{str(port)}"
286+
self._prefix = f"{self.PREFIX_SCHEME + host}:{port!s}"
287287
urlopen_kwargs["assert_same_host"] = False
288288
if proxy_headers:
289289
self._headers.update(proxy_headers)
@@ -501,7 +501,7 @@ class ApplicationModeClient(SupportabilityMixin, HttpClient):
501501

502502

503503
class DeveloperModeClient(SupportabilityMixin, BaseClient):
504-
RESPONSES = {
504+
RESPONSES = { # noqa: RUF012
505505
"preconnect": {"redirect_host": "fake-collector.newrelic.com"},
506506
"agent_settings": [],
507507
"connect": {

newrelic/common/encoding_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def text(self):
486486
if pr:
487487
pr = f"{pr:.6f}".rstrip("0").rstrip(".")
488488

489-
payload = f"0-0-{self['ac']}-{self['ap']}-{self.get('id', '')}-{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{str(self['ti'])}"
489+
payload = f"0-0-{self['ac']}-{self['ap']}-{self.get('id', '')}-{self.get('tx', '')}-{'1' if self.get('sa') else '0'}-{pr}-{self['ti']!s}"
490490
return f"{self.get('tk', self['ac'])}@nr={payload}"
491491

492492
@classmethod

newrelic/common/utilization.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class AWSUtilization(CommonUtilization):
161161
METADATA_HOST = "169.254.169.254"
162162
METADATA_PATH = "/latest/dynamic/instance-identity/document"
163163
METADATA_TOKEN_PATH = "/latest/api/token" # noqa: S105
164-
HEADERS = {"X-aws-ec2-metadata-token-ttl-seconds": "21600"}
164+
HEADERS = {"X-aws-ec2-metadata-token-ttl-seconds": "21600"} # noqa: RUF012
165165
VENDOR_NAME = "aws"
166166
_utilization_data = None
167167

@@ -219,18 +219,18 @@ def fetch(cls):
219219
class AzureUtilization(CommonUtilization):
220220
METADATA_HOST = "169.254.169.254"
221221
METADATA_PATH = "/metadata/instance/compute"
222-
METADATA_QUERY = {"api-version": "2017-03-01"}
222+
METADATA_QUERY = {"api-version": "2017-03-01"} # noqa: RUF012
223223
EXPECTED_KEYS = ("location", "name", "vmId", "vmSize")
224-
HEADERS = {"Metadata": "true"}
224+
HEADERS = {"Metadata": "true"} # noqa: RUF012
225225
VENDOR_NAME = "azure"
226226

227227

228228
class AzureFunctionUtilization(CommonUtilization):
229229
METADATA_HOST = "169.254.169.254"
230230
METADATA_PATH = "/metadata/instance/compute"
231-
METADATA_QUERY = {"api-version": "2017-03-01"}
231+
METADATA_QUERY = {"api-version": "2017-03-01"} # noqa: RUF012
232232
EXPECTED_KEYS = ("faas.app_name", "cloud.region")
233-
HEADERS = {"Metadata": "true"}
233+
HEADERS = {"Metadata": "true"} # noqa: RUF012
234234
VENDOR_NAME = "azurefunction"
235235

236236
@staticmethod
@@ -264,10 +264,10 @@ def get_values(cls, response):
264264

265265
class GCPUtilization(CommonUtilization):
266266
EXPECTED_KEYS = ("id", "machineType", "name", "zone")
267-
HEADERS = {"Metadata-Flavor": "Google"}
267+
HEADERS = {"Metadata-Flavor": "Google"} # noqa: RUF012
268268
METADATA_HOST = "metadata.google.internal"
269269
METADATA_PATH = "/computeMetadata/v1/instance/"
270-
METADATA_QUERY = {"recursive": "true"}
270+
METADATA_QUERY = {"recursive": "true"} # noqa: RUF012
271271
VENDOR_NAME = "gcp"
272272

273273
@classmethod

newrelic/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
)
5151
from newrelic.core.config import Settings, apply_config_setting, default_host, fetch_config_setting
5252

53-
__all__ = ["initialize", "filter_app_factory"]
53+
__all__ = ["filter_app_factory", "initialize"]
5454

5555
_logger = logging.getLogger(__name__)
5656

newrelic/core/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class Agent:
121121

122122
_instance_lock = threading.Lock()
123123
_instance = None
124-
_startup_callables = []
125-
_registration_callables = {}
124+
_startup_callables = [] # noqa: RUF012
125+
_registration_callables = {} # noqa: RUF012
126126

127127
@staticmethod
128128
def run_on_startup(callable): # noqa: A002
@@ -781,7 +781,7 @@ def shutdown_agent(timeout=None):
781781

782782
def register_data_source(source, application=None, name=None, settings=None, **properties):
783783
agent = agent_instance()
784-
agent.register_data_source(source, application and application.name or None, name, settings, **properties)
784+
agent.register_data_source(source, (application and application.name) or None, name, settings, **properties)
785785

786786

787787
def _remove_thread_utilization():

0 commit comments

Comments
 (0)