Skip to content

Commit

Permalink
chore(generatedssupersuper): improve warnings
Browse files Browse the repository at this point in the history
Also, use `logger.warning` instead of `warnings.warn`
  • Loading branch information
sanjayankur31 committed Aug 13, 2024
1 parent 689b9d0 commit 89bd448
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions neuroml/nml/generatedssupersuper.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def add(self, obj=None, hint=None, force=False, validate=True, **kwargs):
else:
if not neuroml.build_time_validation.ENABLED:
self.logger.warning(
f"Adding new {obj.__class__.__name__}: build time validation is globally disabled."
f"Build time validation is globally disabled: adding new {obj.__class__.__name__}."
)
else:
self.logger.warning(
f"Adding new {obj.__class__.__name__}: build time validation is locally disabled."
f"Build time validation is globally disabled: adding new {obj.__class__.__name__}."
)
return obj

Expand Down Expand Up @@ -165,11 +165,11 @@ def component_factory(cls, component_type, validate=True, **kwargs):
else:
if not neuroml.build_time_validation.ENABLED:
cls.logger.warning(
f"Creating new {comp_type_class.__name__}: build time validation is globally disabled."
f"Build time validation is globally disabled: creating new {comp_type_class.__name__}."
)
else:
cls.logger.warning(
f"Creating new {comp_type_class.__name__}: build time validation is locally disabled."
f"Build time validation is globally disabled: creating new {comp_type_class.__name__}."
)
return comp

Expand All @@ -184,16 +184,14 @@ def __add(self, obj, member, force=False):
:type force: bool
"""
import warnings

# A single value, not a list:
if member.get_container() == 0:
if force:
vars(self)[member.get_name()] = obj
else:
if vars(self)[member.get_name()]:
warnings.warn(
"""{} has already been assigned. Use `force=True` to overwrite. Hint: you can make changes to the already added object as required without needing to re-add it because only references to the objects are added, not their values.""".format(
self.logger.warning(
"""Member '{}' has already been assigned. Use `force=True` to overwrite. Hint: you can make changes to the already added object as required without needing to re-add it because only references to the objects are added, not their values.""".format(
member.get_name()
)
)
Expand All @@ -209,7 +207,7 @@ def __add(self, obj, member, force=False):
# There is no use case where the same child would be added
# twice to a component.
if obj in vars(self)[member.get_name()]:
warnings.warn(
self.logger.warning(
"""{} already exists in {}. Use `force=True` to force readdition. Hint: you can make changes to the already added object as required without needing to re-add it because only references to the objects are added, not their values.""".format(
obj, member.get_name()
)
Expand Down

0 comments on commit 89bd448

Please sign in to comment.