Skip to content

Enable pyflakes #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic/admin/record_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pwd

from newrelic.admin import command, usage
from newrelic.common import agent_http, certs, encoding_utils
from newrelic.common import agent_http, encoding_utils
from newrelic.config import initialize
from newrelic.core.config import global_settings

Expand Down
3 changes: 1 addition & 2 deletions newrelic/admin/run_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from newrelic.admin import command, usage
from newrelic.admin import command


@command(
Expand Down Expand Up @@ -62,7 +62,6 @@ def log_message(text, *args):
log_message("%s = %r", name, os.environ.get(name))

from newrelic import __file__ as root_directory
from newrelic import version

root_directory = os.path.dirname(root_directory)
boot_directory = os.path.join(root_directory, "bootstrap")
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/in_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

# Use of these from this module will be deprecated.

from newrelic.common.object_wrapper import InFunctionWrapper, in_function, wrap_in_function
from newrelic.common.object_wrapper import InFunctionWrapper, in_function, wrap_in_function # noqa: F401
6 changes: 2 additions & 4 deletions newrelic/api/object_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

# These have been moved. They are retained here until all references to
# them are moved at which point will mark as deprecated to ensure users
# weren't using them directly.
from newrelic.common.object_names import callable_name
from newrelic.common.object_wrapper import ObjectWrapper, wrap_object
from newrelic.common.object_names import callable_name # noqa: F401
from newrelic.common.object_wrapper import ObjectWrapper, wrap_object # noqa: F401

# From Python 3.X. In older Python versions it fails if attributes do
# not exist and don't maintain a __wrapped__ attribute.
Expand Down
2 changes: 1 addition & 1 deletion newrelic/api/out_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

# Use of these from this module will be deprecated.

from newrelic.common.object_wrapper import OutFunctionWrapper, out_function, wrap_out_function
from newrelic.common.object_wrapper import OutFunctionWrapper, out_function, wrap_out_function # noqa: F401
2 changes: 1 addition & 1 deletion newrelic/api/post_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

# Use of these from this module will be deprecated.

from newrelic.common.object_wrapper import PostFunctionWrapper, post_function, wrap_post_function
from newrelic.common.object_wrapper import PostFunctionWrapper, post_function, wrap_post_function # noqa: F401
2 changes: 1 addition & 1 deletion newrelic/api/pre_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

# Use of these from this module will be deprecated.

from newrelic.common.object_wrapper import PreFunctionWrapper, pre_function, wrap_pre_function
from newrelic.common.object_wrapper import PreFunctionWrapper, pre_function, wrap_pre_function # noqa: F401
2 changes: 1 addition & 1 deletion newrelic/common/async_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def wrapper(*args, **kwargs):
while True:
try:
sent = yield yielded
except GeneratorExit as e:
except GeneratorExit:
await g.aclose()
raise
except BaseException as e:
Expand Down
1 change: 0 additions & 1 deletion newrelic/common/object_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import functools
import inspect
import sys
import types

# Object model terminology for quick reference.
#
Expand Down
2 changes: 0 additions & 2 deletions newrelic/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ def do_interpreter(self):
interactive Python interpreter. Invoke 'exit()' or 'quit()' to
escape the interpreter session."""

enabled = False

_settings = global_settings()

if not _settings.console.allow_interpreter_cmd:
Expand Down
2 changes: 1 addition & 1 deletion newrelic/core/agent_control_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def is_valid_file_delivery_location(file_uri):

return True

except Exception as e:
except Exception:
_logger.warning(
"Configured Agent Control health delivery location is not valid. Health check will not be enabled."
)
Expand Down
3 changes: 0 additions & 3 deletions newrelic/core/internal_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import functools
import sys
import threading
import time
import types

import newrelic.common.object_wrapper

Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/database_aiomysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __await__(self):
while True:
try:
sent = yield yielded
except GeneratorExit as e:
except GeneratorExit:
g.close()
raise
except BaseException as e:
Expand Down
7 changes: 7 additions & 0 deletions newrelic/hooks/database_psycopg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class ConnectionSaveParamsWrapper(DBAPI2ConnectionWrapper):

def __enter__(self):
transaction = current_transaction()
if not transaction:
# Return unwrapped connection if there is no transaction
return self.__wrapped__.__enter__()

name = callable_name(self.__wrapped__.__enter__)
with FunctionTrace(name, source=self.__wrapped__.__enter__):
self.__wrapped__.__enter__()
Expand All @@ -77,6 +81,9 @@ def __enter__(self):

def __exit__(self, exc, value, tb):
transaction = current_transaction()
if not transaction:
return self.__wrapped__.__exit__(exc, value, tb)

name = callable_name(self.__wrapped__.__exit__)
with FunctionTrace(name, source=self.__wrapped__.__exit__):
if exc is None:
Expand Down
12 changes: 5 additions & 7 deletions newrelic/hooks/external_botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def extract_sqs_agent_attrs(instance, *args, **kwargs):
agent_attrs["cloud.region"] = m.group(1)
agent_attrs["cloud.account.id"] = m.group(2)
agent_attrs["messaging.destination.name"] = m.group(3)
except Exception as e:
except Exception:
_logger.debug("Failed to capture AWS SQS info.", exc_info=True)
return agent_attrs

Expand Down Expand Up @@ -117,7 +117,7 @@ def extract_kinesis_agent_attrs(instance, *args, **kwargs):
agent_attrs["cloud.platform"] = "aws_kinesis_data_streams"
return agent_attrs

except Exception as e:
except Exception:
_logger.debug("Failed to capture AWS Kinesis info.", exc_info=True)
return agent_attrs

Expand All @@ -140,7 +140,7 @@ def extract_firehose_agent_attrs(instance, *args, **kwargs):
agent_attrs["cloud.resource_id"] = (
f"arn:aws:firehose:{region}:{account_id}:deliverystream/{stream_name}"
)
except Exception as e:
except Exception:
_logger.debug("Failed to capture AWS Kinesis Delivery Stream (Firehose) info.", exc_info=True)
return agent_attrs

Expand Down Expand Up @@ -786,7 +786,7 @@ async def __anext__(self):
try:
return_val = await self.__wrapped__.__anext__()
record_stream_chunk(self, return_val, transaction)
except StopAsyncIteration as e:
except StopAsyncIteration:
record_events_on_stop_iteration(self, transaction)
raise
except Exception as exc:
Expand Down Expand Up @@ -919,8 +919,6 @@ def handle_chat_completion_event(transaction, bedrock_attrs):
response_id = bedrock_attrs.get("response_id", None)
model = bedrock_attrs.get("model", None)

settings = transaction.settings if transaction.settings is not None else global_settings()

input_message_list = bedrock_attrs.get("input_message_list", [])
output_message_list = bedrock_attrs.get("output_message_list", [])
number_of_messages = (
Expand Down Expand Up @@ -1055,7 +1053,7 @@ def _nr_dynamodb_datastore_trace_wrapper_(wrapped, instance, args, kwargs):
f"arn:{partition}:dynamodb:{region}:{account_id:012d}:table/{_target}"
)

except Exception as e:
except Exception:
_logger.debug("Failed to capture AWS DynamoDB info.", exc_info=True)
trace.agent_attributes.update(agent_attrs)

Expand Down
1 change: 0 additions & 1 deletion newrelic/hooks/external_feedparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import sys
import types

import newrelic.api.external_trace
import newrelic.api.object_wrapper
Expand Down
2 changes: 0 additions & 2 deletions newrelic/hooks/external_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import abc

from newrelic.api.external_trace import ExternalTrace
from newrelic.common.object_wrapper import wrap_function_wrapper

Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/framework_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def wrap_graphql_impl(wrapped, instance, args, kwargs):
try:
with ErrorTrace(ignore=ignore_graphql_duplicate_exception):
result = wrapped(*args, **kwargs)
except Exception as e:
except Exception:
# Execution finished synchronously, exit immediately.
trace.__exit__(*sys.exc_info())
raise
Expand Down
1 change: 0 additions & 1 deletion newrelic/hooks/framework_graphql_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import sys

from newrelic.api.error_trace import ErrorTrace
from newrelic.api.function_trace import FunctionTrace


def nr_coro_execute_name_wrapper(wrapped, result, set_name):
Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/framework_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _nr_sanic_register_middleware_(wrapped, instance, args, kwargs):
callable_name(middleware)
middleware_func = middleware
if hasattr(middleware, "func"):
name = callable_name(middleware.func)
callable_name(middleware.func)
middleware_func = middleware.func

wrapped_middleware = _nr_wrapper_middleware_(attach_to)(middleware_func)
Expand Down
6 changes: 4 additions & 2 deletions newrelic/hooks/framework_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import functools
import inspect
import sys
import textwrap
import time

from newrelic.api.application import application_instance
Expand Down Expand Up @@ -46,7 +45,10 @@ def _store_version_info():
return tornado.version_info


def convert_yielded(*args, **kwargs):
def convert_yielded(*args, **kwargs): # noqa: F811
# Delays import of convert_yielded until this function is called to avoid
# import ordering issues.

global convert_yielded
from tornado.gen import convert_yielded as _convert_yielded

Expand Down
1 change: 0 additions & 1 deletion newrelic/hooks/logger_loguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from newrelic.api.application import application_instance
from newrelic.api.transaction import current_transaction, record_log_event
from newrelic.common.object_wrapper import wrap_function_wrapper
from newrelic.common.package_version_utils import get_package_version_tuple
from newrelic.common.signature import bind_args
from newrelic.core.config import global_settings
from newrelic.hooks.logger_logging import add_nr_linking_metadata
Expand Down
2 changes: 1 addition & 1 deletion newrelic/hooks/messagebroker_confluentkafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def wrap_Consumer_poll(wrapped, instance, args, kwargs):
# Step 2: Poll for records
try:
record = wrapped(*args, **kwargs)
except Exception as e:
except Exception:
if current_transaction():
notice_error()
else:
Expand Down
4 changes: 1 addition & 3 deletions newrelic/hooks/messagebroker_kombu.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ def wrap_Producer_publish(wrapped, instance, args, kwargs):

headers = bound_args["headers"]
headers = headers if headers else {}
value = bound_args["body"]
key = bound_args["routing_key"]
exchange = getattr(bound_args["exchange"], "name", None) or "Default"

transaction.add_messagebroker_info("Kombu", get_package_version("kombu"))
Expand Down Expand Up @@ -257,7 +255,7 @@ def wrap_serialize(wrapped, instance, args, kwargs):
group = "MessageBroker/Kombu/Exchange"
name = f"Named/{exchange}/Serialization/Value"

with FunctionTrace(name=name, group=group) as ft:
with FunctionTrace(name=name, group=group):
return wrapped(*args, **kwargs)


Expand Down
14 changes: 7 additions & 7 deletions newrelic/hooks/mlmodel_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def wrap_asimilarity_search(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
response = await wrapped(*args, **kwargs)
except Exception as exc:
except Exception:
ft.notice_error(attributes={"vector_store_id": search_id})
ft.__exit__(*sys.exc_info())
_create_error_vectorstore_events(transaction, search_id, args, kwargs, linking_metadata, wrapped)
Expand Down Expand Up @@ -221,7 +221,7 @@ def wrap_similarity_search(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
response = wrapped(*args, **kwargs)
except Exception as exc:
except Exception:
ft.notice_error(attributes={"vector_store_id": search_id})
ft.__exit__(*sys.exc_info())
_create_error_vectorstore_events(transaction, search_id, args, kwargs, linking_metadata, wrapped)
Expand Down Expand Up @@ -309,7 +309,7 @@ def wrap_tool_sync_run(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
return_val = wrapped(**run_args)
except Exception as exc:
except Exception:
_record_tool_error(
instance,
transaction,
Expand Down Expand Up @@ -366,7 +366,7 @@ async def wrap_tool_async_run(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
return_val = await wrapped(**run_args)
except Exception as exc:
except Exception:
_record_tool_error(
instance,
transaction,
Expand Down Expand Up @@ -561,7 +561,7 @@ async def wrap_chain_async_run(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
response = await wrapped(input=run_args["input"], config=run_args["config"], **run_args.get("kwargs", {}))
except Exception as exc:
except Exception:
ft.notice_error(attributes={"completion_id": completion_id})
ft.__exit__(*sys.exc_info())
_create_error_chain_run_events(
Expand Down Expand Up @@ -605,7 +605,7 @@ def wrap_chain_sync_run(wrapped, instance, args, kwargs):
linking_metadata = get_trace_linking_metadata()
try:
response = wrapped(input=run_args["input"], config=run_args["config"], **run_args.get("kwargs", {}))
except Exception as exc:
except Exception:
ft.notice_error(attributes={"completion_id": completion_id})
ft.__exit__(*sys.exc_info())
_create_error_chain_run_events(
Expand Down Expand Up @@ -708,7 +708,7 @@ def _create_successful_chain_run_events(
except:
try:
output_message_list = [str(response)]
except Exception as e:
except Exception:
_logger.warning(
"Unable to capture response inside langchain chain instrumentation. No response message event will be captured. Report this issue to New Relic Support.\n%s",
traceback.format_exception(*sys.exc_info()),
Expand Down
Loading
Loading