Skip to content

Commit

Permalink
Fixing tf_agent warning spam.
Browse files Browse the repository at this point in the history
By moving the filter warning to types where it is called before other modules.

PiperOrigin-RevId: 666154650
Change-Id: Ie52b571aff322b2463ad09e7f48764cd71610a0a
  • Loading branch information
esonghori authored and copybara-github committed Aug 22, 2024
1 parent ef9d350 commit a450b4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
4 changes: 4 additions & 0 deletions tf_agents/typing/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
16 changes: 0 additions & 16 deletions tf_agents/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import importlib
import os
from typing import Dict, Optional, Text
import warnings

from absl import logging

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a450b4b

Please sign in to comment.