From a450b4bf33d77fcc31d89194579a7969077aa130 Mon Sep 17 00:00:00 2001 From: Ebrahim Songhori Date: Wed, 21 Aug 2024 20:22:01 -0700 Subject: [PATCH] Fixing tf_agent warning spam. By moving the filter warning to types where it is called before other modules. PiperOrigin-RevId: 666154650 Change-Id: Ie52b571aff322b2463ad09e7f48764cd71610a0a --- tf_agents/typing/types.py | 4 ++++ tf_agents/utils/common.py | 16 ---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/tf_agents/typing/types.py b/tf_agents/typing/types.py index e764339ab..88207ec5d 100644 --- a/tf_agents/typing/types.py +++ b/tf_agents/typing/types.py @@ -22,6 +22,7 @@ import sys import typing from typing import Callable, Iterable, Mapping, Optional, Sequence, Text, TypeVar, Union +import warnings import numpy as np import tensorflow as tf @@ -30,6 +31,9 @@ from tensorflow.python.framework.ops import EagerTensor # TF internal # pylint:enable=g-direct-tensorflow-import +# Filter warnings about comparing literals with "is" (b/229309809). +warnings.filterwarnings('ignore', '.*literal.*', category=SyntaxWarning) + if sys.version_info < (3, 7): ForwardRef = typing._ForwardRef # pylint: disable=protected-access else: diff --git a/tf_agents/utils/common.py b/tf_agents/utils/common.py index 3c15d6c3c..214ea478d 100644 --- a/tf_agents/utils/common.py +++ b/tf_agents/utils/common.py @@ -26,7 +26,6 @@ import importlib import os from typing import Dict, Optional, Text -import warnings from absl import logging @@ -1517,21 +1516,6 @@ def deduped_network_variables(network, *args): return [v for v in network.variables if v not in other_vars] -# Filter warnings about comparing literals with "is" (b/229309809). -warnings.filterwarnings( - 'ignore', - '"is" with a literal. Did you mean "=="?', - category=SyntaxWarning, - module=__name__, -) -warnings.filterwarnings( - 'ignore', - '"is not" with a literal. Did you mean "!="?', - category=SyntaxWarning, - module=__name__, -) - - def safe_has_state(state): """Safely checks `state not in (None, (), [])`.""" # TODO(b/158804957): tf.function changes "s in ((),)" to a tensor bool expr.