Skip to content

Modernization: Convert to new implicit standard for classes #3654

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 1 commit 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
4 changes: 2 additions & 2 deletions examples/dae/ReactionKinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
solver = pyo.SolverFactory('ipopt')


class Reaction(object):
class Reaction:
"""A simple class to hold the stoichiometry of a single reaction

Reaction data is stored in two dictionaries:
Expand Down Expand Up @@ -84,7 +84,7 @@ def _parseTerm(self, x):
return coef, species.strip()


class ReactionNetwork(object):
class ReactionNetwork:
"""A simple object to hold sets of reactions."""

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion examples/pyomo/p-median/solver1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@plugin_factory(pyo.SolverFactory)
class MySolver(object):
class MySolver:
alias('greedy')

# Declare that this is an IOptSolver plugin
Expand Down
2 changes: 1 addition & 1 deletion examples/pyomo/p-median/solver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@plugin_factory
class MySolver(object):
class MySolver:
alias('random')

# Declare that this is an IOptSolver plugin
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/autoslots.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def encode_as_none(encode, val):
else:
return val

class Mixin(object):
class Mixin:
"""Mixin class to configure a class hierarchy to use AutoSlots

Inheriting from this class will set up the automatic generation
Expand Down
34 changes: 17 additions & 17 deletions pyomo/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def NonNegativeFloat(val):
return ans


class In(object):
class In:
"""In(domain, cast=None)
Domain validation class admitting a Container of possible values

Expand Down Expand Up @@ -268,7 +268,7 @@ def domain_name(self):
return f'In{_dn}'


class InEnum(object):
class InEnum:
"""Domain validation class admitting an enum value/name.

This will admit any value that is in the specified Enum, including
Expand Down Expand Up @@ -301,7 +301,7 @@ def domain_name(self):
return f'InEnum[{_domain_name(self._domain)}]'


class IsInstance(object):
class IsInstance:
"""
Domain validator for type checking.

Expand Down Expand Up @@ -365,7 +365,7 @@ def domain_name(self):
return f"IsInstance[{', '.join(class_names)}]"


class ListOf(object):
class ListOf:
"""Domain validator for lists of a specified type

Parameters
Expand Down Expand Up @@ -411,7 +411,7 @@ def domain_name(self):
return f'ListOf[{_dn}]'


class Module(object):
class Module:
"""Domain validator for modules.

Modules can be specified as module objects, by module name,
Expand Down Expand Up @@ -485,7 +485,7 @@ def __call__(self, module_id):
return import_file(path)


class Path(object):
class Path:
"""
Domain validator for a
:py:term:`path-like object <path-like object>`.
Expand Down Expand Up @@ -594,7 +594,7 @@ def __call__(self, data):
return [super(PathList, self).__call__(data)]


class DynamicImplicitDomain(object):
class DynamicImplicitDomain:
"""Implicit domain that can return a custom domain based on the key.

This provides a mechanism for managing plugin-like systems, where
Expand Down Expand Up @@ -810,7 +810,7 @@ def from_enum_or_string(cls, arg):

.. doctest::

>>> class Base(object):
>>> class Base:
... CONFIG = ConfigDict()
... CONFIG.declare('filename', ConfigValue(
... default='input.txt',
Expand Down Expand Up @@ -854,7 +854,7 @@ class will still create ``c`` instances that only have the single

.. doctest::

>>> class Solver(object):
>>> class Solver:
... CONFIG = ConfigDict()
... CONFIG.declare('iterlim', ConfigValue(
... default=10,
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def _value2yaml(prefix, value, obj):
return _str.rstrip()


class _UnpickleableDomain(object):
class _UnpickleableDomain:
def __init__(self, obj):
self._type = type(obj).__name__
self._name = obj.name(True)
Expand Down Expand Up @@ -1410,7 +1410,7 @@ def _item_body_cb(self, indent, obj):
return types.MethodType(_item_body_cb, formatter)


class ConfigFormatter(object):
class ConfigFormatter:
def _initialize(self, indent_spacing, width, visibility):
self.out = io.StringIO()
self.indent_spacing = indent_spacing
Expand Down Expand Up @@ -1565,7 +1565,7 @@ def add_docstring_list(docstring, configdict, indent_by=4):
)


class document_kwargs_from_configdict(object):
class document_kwargs_from_configdict:
"""Decorator to append the documentation of a ConfigDict to the docstring

This adds the documentation of the specified :py:class:`ConfigDict`
Expand Down Expand Up @@ -1600,7 +1600,7 @@ class document_kwargs_from_configdict(object):
>>> from pyomo.common.config import (
... ConfigDict, ConfigValue, document_kwargs_from_configdict
... )
>>> class MyClass(object):
>>> class MyClass:
... CONFIG = ConfigDict()
... CONFIG.declare('iterlim', ConfigValue(
... default=3000,
Expand Down Expand Up @@ -1676,7 +1676,7 @@ def __call__(self, fcn):
return fcn


class UninitializedMixin(object):
class UninitializedMixin:
"""Mixin class to support delayed data initialization.

This mixin can be used to create a derived Config class that hides
Expand Down Expand Up @@ -1743,7 +1743,7 @@ def _data(self, value):
self._data = value


class ConfigBase(object):
class ConfigBase:
# Note: __getstate__ relies on this field ordering. Do not change.
__slots__ = (
'_parent',
Expand All @@ -1763,7 +1763,7 @@ class ConfigBase(object):
# we can tell if an argument is provided (and we can't use None as
# None is a valid user-specified argument). Making it a class helps
# when Config objects are pickled.
class NoArgument(object):
class NoArgument:
pass

def __init__(
Expand Down Expand Up @@ -2293,7 +2293,7 @@ def _setter(self, value):
self._data = _data


class MarkImmutable(object):
class MarkImmutable:
"""
Mark instances of ConfigValue as immutable.

Expand Down
8 changes: 4 additions & 4 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SUPPRESS_DEPENDENCY_WARNINGS = False


class ModuleUnavailable(object):
class ModuleUnavailable:
"""Mock object that raises :py:class:`.DeferredImportError` upon attribute access

This object is returned by :py:func:`attempt_import()` in lieu of
Expand Down Expand Up @@ -129,7 +129,7 @@ def generate_import_warning(self, logger='pyomo.common'):
self.log_import_warning(logger)


class DeferredImportModule(object):
class DeferredImportModule:
"""Mock module object to support the deferred import of a module.

This object is returned by :py:func:`attempt_import()` in lieu of
Expand Down Expand Up @@ -281,7 +281,7 @@ def __new__(cls, *args, **kwargs):
return UnavailableBase


class _DeferredImportIndicatorBase(object):
class _DeferredImportIndicatorBase:
def __and__(self, other):
return _DeferredAnd(self, other)

Expand Down Expand Up @@ -857,7 +857,7 @@ def declare_deferred_modules_as_importable(globals_dict):
return declare_modules_as_importable(globals_dict).__exit__(None, None, None)


class declare_modules_as_importable(object):
class declare_modules_as_importable:
"""Make all :py:class:`ModuleType` and :py:class:`DeferredImportModules`
importable through the ``globals_dict`` context.

Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class RenamedClass(type):
Examples
--------
>>> from pyomo.common.deprecation import RenamedClass
>>> class NewClass(object):
>>> class NewClass:
... pass
>>> class OldClass(metaclass=RenamedClass):
... __renamed__new_class__ = NewClass
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
DownloadFactory = pyomo.common.Factory('library downloaders')


class FileDownloader(object):
class FileDownloader:
_os_version = None

def __init__(self, insecure=False, cacert=None):
Expand Down
10 changes: 5 additions & 5 deletions pyomo/common/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _load_dll(name, timeout=10):
_load_dll.pool = None


class _RestorableEnvironInterface(object):
class _RestorableEnvironInterface:
"""Interface to track environment changes and restore state"""

def __init__(self, dll):
Expand Down Expand Up @@ -160,7 +160,7 @@ def __delitem__(self, key):
self.dll.putenv_s(key, b'')


class _OSEnviron(object):
class _OSEnviron:
"""Helper class to proxy a "DLL-like" interface to os.environ"""

_libname = 'os.environ'
Expand Down Expand Up @@ -205,7 +205,7 @@ def wputenv_s(self, key, val):
os.environ[key] = val


class _MsvcrtDLL(object):
class _MsvcrtDLL:
"""Helper class to manage the interface with the MSVCRT runtime"""

def __init__(self, name):
Expand Down Expand Up @@ -280,7 +280,7 @@ def get_env_dict(self):
return ans


class _Win32DLL(object):
class _Win32DLL:
"""Helper class to manage the interface with the Win32 runtime"""

def __init__(self, name):
Expand Down Expand Up @@ -381,7 +381,7 @@ def get_env_dict(self):
return ans


class CtypesEnviron(object):
class CtypesEnviron:
"""A context manager for managing environment variables

This class provides a simplified interface for consistently setting
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ___________________________________________________________________________


class Factory(object):
class Factory:
"""
A class that is used to define a factory for objects.

Expand Down
4 changes: 2 additions & 2 deletions pyomo/common/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def import_file(path, clear_cache=False, infer_package=True, module_name=None):
return module


class PathData(object):
class PathData:
"""An object for storing and managing a :py:class:`PathManager` path"""

def __init__(self, manager, name):
Expand Down Expand Up @@ -610,7 +610,7 @@ def executable(self, value):
self.set_path(value)


class PathManager(object):
class PathManager:
"""The PathManager defines a registry class for path locations

The :py:class:`PathManager` defines a class very similar to the
Expand Down
2 changes: 1 addition & 1 deletion pyomo/common/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def tabular_writer(ostream, prefix, data, header, row_generator):
)


class StreamIndenter(object):
class StreamIndenter:
"""
Mock-up of a file-like object that wraps another file-like object
and indents all data using the specified string before passing it to
Expand Down
4 changes: 2 additions & 2 deletions pyomo/common/gc_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pyomo.common.multithread import MultiThreadWrapper


class __PauseGCCompanion(object):
class __PauseGCCompanion:
def __init__(self):
self._stack_depth = 0

Expand All @@ -41,7 +41,7 @@ def __init__(self):
# the GC will be re-enabled (if it was not initially disabled). It is
# safe to nest instances of PauseGC That is, you don't have to worry
# if an outer function/method has its own instance of PauseGC.
class PauseGC(object):
class PauseGC:
__slots__ = ("reenable_gc", "stack_pointer")

def __init__(self):
Expand Down
10 changes: 5 additions & 5 deletions pyomo/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def emit(self, record):
self.stream = orig


class Preformatted(object):
class Preformatted:
__slots__ = ('msg',)

def __init__(self, msg):
Expand All @@ -250,7 +250,7 @@ def __repr__(self):
return f'Preformatted({self.msg!r})'


class _GlobalLogFilter(object):
class _GlobalLogFilter:
def __init__(self):
self.logger = logging.getLogger()

Expand Down Expand Up @@ -292,7 +292,7 @@ def __init__(self, base='', stream=None, level=logging.NOTSET, verbosity=None):
self.setFormatter(LegacyPyomoFormatter(base=base, verbosity=verbosity))


class LoggingIntercept(object):
class LoggingIntercept:
r"""Context manager for intercepting messages sent to a log stream

This class is designed to enable easy testing of log messages.
Expand Down Expand Up @@ -461,7 +461,7 @@ def redirect_streams(self, redirects):
yield _LastResortRedirector(redirects[fd].original_fd)


class _StreamRedirector(object):
class _StreamRedirector:
def __init__(self, handler, fd):
self.handler = handler
self.fd = fd
Expand All @@ -488,7 +488,7 @@ def __exit__(self, et, ev, tb):
self.handler.stream = self.orig_stream


class _LastResortRedirector(object):
class _LastResortRedirector:
def __init__(self, fd):
self.fd = fd
self.local_fd = None
Expand Down
Loading
Loading