mirror of
https://github.com/gnuradio/gnuradio-companion.git
synced 2025-12-10 17:46:12 -06:00
All of the removed `from __future__ import` were needed in older versions of Python (mostly 2.5.x and below) but later became mandatory in most versions of Python 3 hence are not necessary anymore. More specifically, according to __future__.py[1]: - unicode_literals is part of Python since versions 2.6.0 and 3.0.0; - print_function is part of Python since versions 2.6.0 and 3.0.0; - absolute_import is part of Python since versions 2.5.0 and 3.0.0; - division is part of Python since versions 2.2.0 and 3.0.0; Get rid of those unnecessary imports to slightly clean up the codebase. [1] https://github.com/python/cpython/blob/master/Lib/__future__.py
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
# Copyright 2008-2017 Free Software Foundation, Inc.
|
|
# This file is part of GNU Radio
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
#
|
|
|
|
|
|
|
|
class TemplateArg(str):
|
|
"""
|
|
A cheetah template argument created from a param.
|
|
The str of this class evaluates to the param's to code method.
|
|
The use of this class as a dictionary (enum only) will reveal the enum opts.
|
|
The __call__ or () method can return the param evaluated to a raw python data type.
|
|
"""
|
|
|
|
def __new__(cls, param):
|
|
value = param.to_code()
|
|
instance = str.__new__(cls, value)
|
|
setattr(instance, '_param', param)
|
|
return instance
|
|
|
|
def __getitem__(self, item):
|
|
return str(self._param.get_opt(item)) if self._param.is_enum() else NotImplemented
|
|
|
|
def __getattr__(self, item):
|
|
if not self._param.is_enum():
|
|
raise AttributeError()
|
|
try:
|
|
return str(self._param.get_opt(item))
|
|
except KeyError:
|
|
raise AttributeError()
|
|
|
|
def __str__(self):
|
|
return str(self._param.to_code())
|
|
|
|
def __call__(self):
|
|
return self._param.get_evaluated()
|