Skip to content

Commit

Permalink
#253 - Do not emit warnings during merge
Browse files Browse the repository at this point in the history
We now do not warn when redefining features during merge, as that leads too many warnings, especially when merging very similar type systems.
  • Loading branch information
jcklie committed Mar 25, 2022
1 parent 339c27b commit ff5fddc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cassis/typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,13 @@ def get_feature(self, name: str) -> Optional[Feature]:
else:
return None

def _add_feature(self, feature: Feature, inherited: bool = False):
def _add_feature(self, feature: Feature, inherited: bool = False, warn: bool = True):
"""Add the given feature to his type.
Args:
feature: The feature
inherited: Indicates whether this feature is inherited from a parent or not
warn: Emit a user warning when exactly redefining features
"""
# Clear the feature cache when adding a new feature. Note that this method is also called by supertypes when
Expand All @@ -578,26 +579,26 @@ def _add_feature(self, feature: Feature, inherited: bool = False):
if feature.name in target:
redefined_feature = target[feature.name]

if redefined_feature == feature:
msg = f"Feature with name [{feature.name}] already exists in [{self.name}]!"
warnings.warn(msg)
else:
if redefined_feature != feature:
msg = "Feature with name [{}] already exists in [{}] but is redefined differently!".format(
feature.name, self.name
)
raise ValueError(msg)
elif warn:
msg = f"Feature with name [{feature.name}] already exists in [{self.name}]!"
warnings.warn(msg)
return

# Check that feature is not redefined on parent type
if feature.name in self._inherited_features:
redefined_feature = self._inherited_features[feature.name]

if redefined_feature == feature:
msg = f"Feature with name [{feature.name}] already exists in parent!"
warnings.warn(msg)
else:
if redefined_feature != feature:
msg = f"Feature with name [{feature.name}] already exists in parent but is redefined!"
raise ValueError(msg)
elif warn:
msg = f"Feature with name [{feature.name}] already exists in parent!"
warnings.warn(msg)
return

target[feature.name] = feature
Expand Down Expand Up @@ -1423,7 +1424,7 @@ def merge_typesystems(*typesystems: TypeSystem) -> TypeSystem:
)

for feature in t.features:
created_type._add_feature(feature)
created_type._add_feature(feature, warn=False)
else:
# Type is already defined
existing_type = merged_ts.get_type(t.name)
Expand All @@ -1447,7 +1448,7 @@ def merge_typesystems(*typesystems: TypeSystem) -> TypeSystem:

# If the type is already defined, merge features
for feature in t.features:
existing_type._add_feature(feature)
existing_type._add_feature(feature, warn=False)

merged_types.add(t.name)
updated_type_list.remove(t)
Expand Down

0 comments on commit ff5fddc

Please sign in to comment.