Skip to content

Commit

Permalink
[Python] Include class and method name in deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jul 2, 2023
1 parent 21e5982 commit 493a63d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 80 deletions.
44 changes: 23 additions & 21 deletions interfaces/cython/cantera/_onedim.pyx
Expand Up @@ -438,8 +438,8 @@ cdef class ReactingSurface1D(Boundary1D):
def __init__(self, _SolutionBase phase, name=None):
self._weakref_proxy = _WeakrefProxy()
if phase.phase_of_matter == "gas":
warnings.warn("Starting in Cantera 3.0, parameter 'phase' should "
"reference surface instead of gas phase.", DeprecationWarning)
warnings.warn("ReactingSurface1D: Starting in Cantera 3.0, parameter 'phase'"
" should reference surface instead of gas phase.", DeprecationWarning)
super().__init__(phase)
if name is not None:
self.name = name
Expand Down Expand Up @@ -477,8 +477,9 @@ cdef class ReactingSurface1D(Boundary1D):
Method to be removed after Cantera 3.0; set `Kinetics` when instantiating
`ReactingSurface1D` instead.
"""
warnings.warn("Method to be removed after Cantera 3.0; set 'Kinetics' when "
"instantiating 'ReactingSurface1D' instead.", DeprecationWarning)
warnings.warn("ReactingSurface1D.set_kinetics: Method to be removed after "
"Cantera 3.0; set 'Kinetics' when instantiating 'ReactingSurface1D' "
"instead.", DeprecationWarning)
if pystr(kin.kinetics.kineticsType()) not in ("surface", "edge"):
raise TypeError('Kinetics object must be derived from '
'InterfaceKinetics.')
Expand Down Expand Up @@ -535,8 +536,8 @@ cdef class _FlowBase(Domain1D):
Method to be removed after Cantera 3.0. Replaceable by `transport_model`
"""
warnings.warn("Method to be removed after Cantera 3.0; use property "
"'transport_model' instead.", DeprecationWarning)
warnings.warn("_FlowBase.set_transport: Method to be removed after Cantera 3.0;"
" use property 'transport_model' instead.", DeprecationWarning)
self._weakref_proxy = _WeakrefProxy()
self.gas._references[self._weakref_proxy] = True
self.gas = phase
Expand Down Expand Up @@ -623,8 +624,8 @@ cdef class _FlowBase(Domain1D):
"""
def __get__(self):
warnings.warn(
"Property getter to change after Cantera 3.0.\nFor new behavior, use "
"'get_settings3'.", DeprecationWarning)
"_FlowBase.settings: Property getter to change after Cantera 3.0.\n"
"For new behavior, use 'get_settings3'.", DeprecationWarning)

out = {
'Domain1D_type': type(self).__name__,
Expand Down Expand Up @@ -653,8 +654,8 @@ cdef class _FlowBase(Domain1D):

return out
def __set__(self, meta):
warnings.warn("Property setter to be removed after Cantera 3.0. "
"Replaceable by individual setters.", DeprecationWarning)
warnings.warn("_FlowBase.settings: Property setter to be removed after "
"Cantera 3.0. Replaceable by individual setters.", DeprecationWarning)

# boundary emissivities
if 'emissivity_left' in meta or 'emissivity_right' in meta:
Expand Down Expand Up @@ -875,8 +876,8 @@ cdef class IdealGasFlow(_FlowBase):
_domain_type = "gas-flow"

def __init__(self, *args, **kwargs):
warnings.warn("Class to be removed after Cantera 3.0; use 'FreeFlow', "
"'AxisymmetricFlow' or 'UnstrainedFlow' instead.",
warnings.warn("Class 'IdealGasFlow' to be removed after Cantera 3.0; use "
"'FreeFlow', 'AxisymmetricFlow' or 'UnstrainedFlow' instead.",
DeprecationWarning)
super().__init__(*args, **kwargs)

Expand All @@ -895,8 +896,8 @@ cdef class IonFlow(_FlowBase):
_domain_type = "ion-flow"

def __init__(self, *args, **kwargs):
warnings.warn("Class to be removed after Cantera 3.0; use 'FreeFlow', "
"'AxisymmetricFlow' or 'UnstrainedFlow' instead.",
warnings.warn("Class 'IonFlow' to be removed after Cantera 3.0; use 'FreeFlow',"
" 'AxisymmetricFlow' or 'UnstrainedFlow' instead.",
DeprecationWarning)
super().__init__(*args, **kwargs)

Expand All @@ -908,8 +909,8 @@ cdef class IonFlow(_FlowBase):
- ``stage == 2``: the electric field equation is solved, and the drift flux for
ionized species is evaluated
"""
warnings.warn("Method to be removed after Cantera 3.0; use "
"'solving_stage' property instead.", DeprecationWarning)
warnings.warn("IonFlow.set_solving_stage: Method to be removed after Cantera "
"3.0; use 'solving_stage' property instead.", DeprecationWarning)
self.solving_stage = stage


Expand Down Expand Up @@ -1173,7 +1174,8 @@ cdef class Sim1D:
interface to the C++ core, except for `FlameBase.from_solution_array`,
which itself is deprecated due to a pending removal of ``h5py`` support.
"""
warnings.warn("Method to be removed after Cantera 3.0.", DeprecationWarning)
warnings.warn("Sim1D.restore_data: Method to be removed after Cantera 3.0.",
DeprecationWarning)
idom = self.domain_index(domain)
dom = self.domains[idom]
T, P, Y = states
Expand Down Expand Up @@ -1629,8 +1631,8 @@ cdef class Sim1D:
Argument loglevel is no longer supported
"""
if loglevel is not None:
warnings.warn("Argument 'loglevel' is deprecated and will be ignored.",
DeprecationWarning)
warnings.warn("Sim1D.save: Argument 'loglevel' is deprecated and will be "
"ignored.", DeprecationWarning)
self.sim.save(stringify(str(filename)), stringify(name),
stringify(description), overwrite, compression, stringify(basis))

Expand All @@ -1657,8 +1659,8 @@ cdef class Sim1D:
Implemented return value for meta data; loglevel is no longer supported
"""
if loglevel is not None:
warnings.warn("Argument 'loglevel' is deprecated and will be ignored.",
DeprecationWarning)
warnings.warn("Sim1D.restore: Argument 'loglevel' is deprecated and will be"
" ignored.", DeprecationWarning)
cdef CxxAnyMap header
header = self.sim.restore(stringify(str(filename)), stringify(name))
self._initialized = True
Expand Down
12 changes: 6 additions & 6 deletions interfaces/cython/cantera/composite.py
Expand Up @@ -1202,7 +1202,7 @@ def write_csv(self, filename, cols=None, *args, **kwargs):
Method to be removed after Cantera 3.0; superseded by `save`. Note that
`write_csv` does not support escaping of commas within string entries.
"""
warnings.warn("'write_csv' is superseded by 'save' and will be removed "
warnings.warn("SolutionArray.write_csv: Superseded by 'save' and will be removed "
"after Cantera 3.0.", DeprecationWarning)
data_dict = self.collect_data(*args, cols=cols, tabular=True, **kwargs)
data = np.hstack([d[:, np.newaxis] for d in data_dict.values()])
Expand Down Expand Up @@ -1430,9 +1430,9 @@ def write_hdf(self, filename, *args, cols=None, group=None, subgroup=None,
the call is redirected to `save` in order to prevent the creation of a file
with legacy HDF format.
"""
warnings.warn("Method to be removed after Cantera 3.0; use 'save' instead.\n"
"Note that the call is redirected to 'save' in order to prevent the "
"creation of a file with legacy HDF format;\nas a consequence, "
warnings.warn("SolutionArray.write_hdf: To be removed after Cantera 3.0; use "
"'save' instead.\n Note that the call is redirected to 'save' in order to "
"prevent the creation of a file with legacy HDF format;\nas a consequence, "
"some options are no longer supported.", DeprecationWarning)

if group is None:
Expand Down Expand Up @@ -1476,8 +1476,8 @@ def read_hdf(self, filename, group=None, subgroup=None, force=False, normalize=T
if _h5py is None:
_import_h5py()

warnings.warn("Method to be removed after Cantera 3.0; use 'restore' instead.",
DeprecationWarning)
warnings.warn("SolutionArray.read_hdf: Method to be removed after Cantera 3.0; "
"use 'restore' instead.", DeprecationWarning)

with _h5py.File(filename, 'r') as hdf:

Expand Down
10 changes: 6 additions & 4 deletions interfaces/cython/cantera/kinetics.pyx
Expand Up @@ -299,8 +299,9 @@ cdef class Kinetics(_SolutionBase):
`Kinetics.reactant_stoich_coeffs`
"""
def __get__(self):
warnings.warn("Method to be removed after Cantera 3.0; use property "
"'reactant_stoich_coeffs' instead.", DeprecationWarning)
warnings.warn("Kinetics.reactant_stoich_coeffs3: To be removed after "
"Cantera 3.0; use property 'reactant_stoich_coeffs' instead.",
DeprecationWarning)
return self.reactant_stoich_coeffs

property product_stoich_coeffs:
Expand Down Expand Up @@ -333,8 +334,9 @@ cdef class Kinetics(_SolutionBase):
`Kinetics.product_stoich_coeffs`
"""
def __get__(self):
warnings.warn("Method to be removed after Cantera 3.0; use property "
"'product_stoich_coeffs' instead.", DeprecationWarning)
warnings.warn("Kinetics.product_stoich_coeffs3: Method to be removed after "
"Cantera 3.0; use property 'product_stoich_coeffs' instead.",
DeprecationWarning)
return self.product_stoich_coeffs

property product_stoich_coeffs_reversible:
Expand Down
42 changes: 19 additions & 23 deletions interfaces/cython/cantera/onedim.py
Expand Up @@ -54,8 +54,8 @@ def other_components(self, domain=None):
Method to be removed after Cantera 3.0. After moving SolutionArray HDF
export to the C++ core, this method is unused.
"""
warnings.warn("Method to be removed after Cantera 3.0 (unused).",
DeprecationWarning)
warnings.warn("FlameBase.other_components: Method to be removed after "
"Cantera 3.0 (unused).", DeprecationWarning)
if domain is None:
return self._other

Expand Down Expand Up @@ -384,8 +384,8 @@ def solution(self, component, point=None):
To be removed after Cantera 3.0 to avoid conflation with `Solution`.
Replaceable by `profile` or `value`.
"""
warnings.warn("Method 'solution' to be removed after Cantera 3.0. "
"Replaceable by 'profile' or 'value'.")
warnings.warn("FlameBase.solution: To be removed after Cantera 3.0. "
"Replaceable by 'profile' or 'value'.", DeprecationWarning)
if point is None:
return self.profile(self.flame, component)
else:
Expand Down Expand Up @@ -421,7 +421,7 @@ def write_csv(self, filename, species='X', quiet=True, normalize=True):
Method to be removed after Cantera 3.0; superseded by `save`.
"""
warnings.warn("'write_csv' is superseded by 'save' and will be removed "
warnings.warn("FlameBase.write_csv: Superseded by 'save'. To be removed "
"after Cantera 3.0.", DeprecationWarning)

# save data
Expand Down Expand Up @@ -465,9 +465,8 @@ def to_solution_array(self, domain=None, normalize=True):
Method to be removed after Cantera 3.0; superseded by `to_array`.
"""
warnings.warn(
"Method to be removed after Cantera 3.0. Replaceable by 'to_array'.",
DeprecationWarning)
warnings.warn("FlameBase.to_solution_array: To be removed after Cantera 3.0. "
"Replaceable by 'to_array'.", DeprecationWarning)
return self.to_array(domain, normalize)

def from_array(self, arr, domain=None):
Expand Down Expand Up @@ -497,9 +496,8 @@ def from_solution_array(self, arr, domain=None):
Method to be removed after Cantera 3.0; replaced by `from_array`.
"""
warnings.warn(
"Method to be removed after Cantera 3.0. Replaced by 'from_array'.",
DeprecationWarning)
warnings.warn("FlameBase.from_solution_array: To be removed after Cantera 3.0. "
"Replaced by 'from_array'.", DeprecationWarning)
if domain is None:
domain = self.flame
else:
Expand Down Expand Up @@ -635,9 +633,10 @@ def write_hdf(self, filename, *args, group=None, species='X', mode='a',
the call is redirected to `save` in order to prevent the creation of a file
with deprecated HDF format.
"""
warnings.warn("Method to be removed after Cantera 3.0; use 'save' instead.\n"
"Note that the call is redirected to 'save' in order to prevent the "
"creation of a file with deprecated HDF format.", DeprecationWarning)
warnings.warn("FlameBase.write_hdf: To be removed after Cantera 3.0; use "
"'save' instead.\nNote that the call is redirected to 'save' in order to "
"prevent the creation of a file with deprecated HDF format.",
DeprecationWarning)

self.save(filename, name=group, description=description,
compression=compression_opts)
Expand Down Expand Up @@ -665,9 +664,8 @@ def read_hdf(self, filename, group=None, restore_boundaries=True, normalize=True
Method to be removed after Cantera 3.0; superseded by `restore`.
"""
warnings.warn(
"Method to be removed after Cantera 3.0; use 'restore' instead.",
DeprecationWarning)
warnings.warn("FlameBase.read_hdf: To be removed after Cantera 3.0; use "
"'restore' instead.", DeprecationWarning)

if restore_boundaries:
domains = range(3)
Expand All @@ -694,9 +692,8 @@ def settings(self):
To be removed after Cantera 3.0. The getter is replaceable by
`Domain1D.settings`; for the setter, use setters for individual settings.
"""
warnings.warn(
"Property 'settings' to be removed after Cantera 3.0. Access settings from "
"domains instead.", DeprecationWarning)
warnings.warn("FlameBase.settings: to be removed after Cantera 3.0. Access "
"settings from domains instead.", DeprecationWarning)
out = {'Sim1D_type': type(self).__name__}
out['transport_model'] = self.transport_model
out['energy_enabled'] = self.energy_enabled
Expand All @@ -711,9 +708,8 @@ def settings(self):

@settings.setter
def settings(self, s):
warnings.warn(
"Property 'settings' to be removed after Cantera 3.0. Use individual "
"setters instead.", DeprecationWarning)
warnings.warn("FlameBase.settings: To be removed after Cantera 3.0. Use "
"individual setters instead.", DeprecationWarning)
# simple setters
attr = {'transport_model',
'energy_enabled', 'soret_enabled', 'radiation_enabled',
Expand Down

0 comments on commit 493a63d

Please sign in to comment.