From: whitequark Date: Sat, 26 Jan 2019 15:43:00 +0000 (+0000) Subject: compat: suppress deprecation warnings that are internal or during test. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78c3d1ae66c8aa7b3998bb8ece2d0c68dcdd6f8d;p=nmigen.git compat: suppress deprecation warnings that are internal or during test. --- diff --git a/nmigen/compat/genlib/fsm.py b/nmigen/compat/genlib/fsm.py index 509c9ef..844d323 100644 --- a/nmigen/compat/genlib/fsm.py +++ b/nmigen/compat/genlib/fsm.py @@ -1,6 +1,6 @@ -import warnings from collections import OrderedDict +from ...tools import _ignore_deprecated from ...hdl.xfrm import ValueTransformer, StatementTransformer from ...hdl.ast import * from ..fhdl.module import CompatModule, CompatFinalizeError @@ -153,6 +153,7 @@ class FSM(CompatModule): self.sync += signal.eq(self.before_leaving(state)) return signal + @_ignore_deprecated def do_finalize(self): nstates = len(self.actions) self.encoding = dict((s, n) for n, s in enumerate(self.actions.keys())) @@ -178,11 +179,10 @@ class FSM(CompatModule): def _finalize_sync(self, ls): cases = dict((self.encoding[k], ls.on_statement(v)) for k, v in self.actions.items() if v) - with warnings.catch_warnings(): - self.comb += [ - self.next_state.eq(self.state), - Case(self.state, cases).makedefault(self.encoding[self.reset_state]) - ] - self.sync += self.state.eq(self.next_state) - for register, next_value_ce, next_value in ls.registers: - self.sync += If(next_value_ce, register.eq(next_value)) + self.comb += [ + self.next_state.eq(self.state), + Case(self.state, cases).makedefault(self.encoding[self.reset_state]) + ] + self.sync += self.state.eq(self.next_state) + for register, next_value_ce, next_value in ls.registers: + self.sync += If(next_value_ce, register.eq(next_value)) diff --git a/nmigen/test/compat/support.py b/nmigen/test/compat/support.py index 3de3276..1dd5601 100644 --- a/nmigen/test/compat/support.py +++ b/nmigen/test/compat/support.py @@ -1,10 +1,12 @@ +from ...tools import _ignore_deprecated from ...compat import * from ...compat.fhdl import verilog class SimCase: def setUp(self, *args, **kwargs): - self.tb = self.TestBench(*args, **kwargs) + with _ignore_deprecated(): + self.tb = self.TestBench(*args, **kwargs) def test_to_verilog(self): verilog.convert(self.tb) diff --git a/nmigen/tools.py b/nmigen/tools.py index 0cdbbce..25b6893 100644 --- a/nmigen/tools.py +++ b/nmigen/tools.py @@ -1,6 +1,8 @@ -from collections.abc import Iterable +import contextlib import functools import warnings +from collections.abc import Iterable +from contextlib import contextmanager __all__ = ["flatten", "union", "log2_int", "bits_for", "deprecated"] @@ -54,6 +56,23 @@ def deprecated(message, stacklevel=2): return decorator +def _ignore_deprecated(f=None): + if f is None: + @contextlib.contextmanager + def context_like(): + with warnings.catch_warnings(): + warnings.filterwarnings(action="ignore", category=DeprecationWarning) + yield + return context_like() + else: + @functools.wraps(f) + def decorator_like(*args, **kwargs): + with warnings.catch_warnings(): + warnings.filterwarnings(action="ignore", category=DeprecationWarning) + f(*args, **kwargs) + return decorator_like + + def extend(cls): def decorator(f): if isinstance(f, property):