-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Raise on duplicated aliases #291
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,6 +84,10 @@ class Metadata: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rules: dict[str, RuleFactory] = field(default_factory=dict) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def update(self, other: Self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if duplicated_column_names := self.columns.keys() & other.columns.keys(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ImplementationError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Columns {duplicated_column_names} are duplicated." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+90
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if duplicated_column_names := self.columns.keys() & other.columns.keys(): | |
| raise ImplementationError( | |
| f"Columns {duplicated_column_names} are duplicated." | |
| ) | |
| """Merge another Metadata instance into this one. | |
| Overlapping keys are allowed if and only if they refer to the *same* | |
| underlying object. This accommodates multiple-inheritance / diamond | |
| patterns where the same base schema is visited more than once. | |
| """ | |
| # Detect conflicting column definitions: same name, different Column instance | |
| duplicated_column_names = self.columns.keys() & other.columns.keys() | |
| conflicting_columns = { | |
| name | |
| for name in duplicated_column_names | |
| if self.columns[name] is not other.columns[name] | |
| } | |
| if conflicting_columns: | |
| raise ImplementationError( | |
| f"Columns {conflicting_columns} are duplicated with conflicting definitions." | |
| ) | |
| # Detect conflicting rule factories: same name, different object | |
| duplicated_rule_names = self.rules.keys() & other.rules.keys() | |
| conflicting_rules = { | |
| name | |
| for name in duplicated_rule_names | |
| if self.rules[name] is not other.rules[name] | |
| } | |
| if conflicting_rules: | |
| raise ImplementationError( | |
| f"Rules {conflicting_rules} are duplicated with conflicting definitions." | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception message uses the raw set representation of
duplicated_column_names(derived from key-set intersection). For multiple duplicates this will be non-deterministically ordered, which can make debugging and tests brittle. Consider formatting a stable, sorted list of duplicated names (and optionally quoting each name) instead of interpolating the set directly.