Skip to content

Commit

Permalink
chore: Do not add methods to warning classes per style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed May 9, 2024
1 parent 9b9c59c commit 85e7e6b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ocdskit/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def combine_record_packages(packages, uri='', publisher=None, published_date='',
if 'records' in package:
output['records'].extend(package['records'])
else:
warnings.warn(MissingRecordsWarning(i))
warnings.warn(f'item {i} has no "records" field (check that it is a record package)')
if 'packages' in package:
output['packages'].update(dict.fromkeys(package['packages']))

Expand Down Expand Up @@ -122,7 +122,7 @@ def combine_release_packages(packages, uri='', publisher=None, published_date=''
if 'releases' in package:
output['releases'].extend(package['releases'])
else:
warnings.warn(MissingReleasesWarning(i))
warnings.warn(f'item {i} has no "releases" field (check that it is a release package)')

if publisher:
output['publisher'] = publisher
Expand Down
9 changes: 0 additions & 9 deletions ocdskit/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,10 @@ class OCDSKitWarning(UserWarning):
class MissingRecordsWarning(OCDSKitWarning):
"""Used when the "records" field is missing from a record package when combining packages"""

def __str__(self):
return 'item {0} has no "records" field (check that it is a record package)'.format(*self.args)


class MissingReleasesWarning(OCDSKitWarning):
"""Used when the "releases" field is missing from a release package when combining packages"""

def __str__(self):
return 'item {0} has no "releases" field (check that it is a release package)'.format(*self.args)


class MergeErrorWarning(OCDSKitWarning):
"""Used when downgrading an OCDS Merge exception to a warning"""

def __str__(self):
return '{0}'.format(*self.args)
4 changes: 2 additions & 2 deletions ocdskit/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def output_records(
record['versionedRelease'] = merger.create_versioned_release(releases)
except InconsistentTypeError as e:
if convert_exceptions_to_warnings:
warnings.warn(MergeErrorWarning(e))
warnings.warn(MergeErrorWarning(str(e)))
else:
raise

Expand Down Expand Up @@ -228,7 +228,7 @@ def output_releases(
yield merger.create_compiled_release(releases)
except InconsistentTypeError as e:
if convert_exceptions_to_warnings:
warnings.warn(MergeErrorWarning(e))
warnings.warn(MergeErrorWarning(str(e)))
else:
raise

Expand Down

0 comments on commit 85e7e6b

Please sign in to comment.