Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/npm/utils.py
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | def extract_npm_package_author(package_json): | ||||
def _author_str(author_data): | def _author_str(author_data): | ||||
if type(author_data) is dict: | if type(author_data) is dict: | ||||
author_str = '' | author_str = '' | ||||
if 'name' in author_data: | if 'name' in author_data: | ||||
author_str += author_data['name'] | author_str += author_data['name'] | ||||
if 'email' in author_data: | if 'email' in author_data: | ||||
author_str += ' <%s>' % author_data['email'] | author_str += ' <%s>' % author_data['email'] | ||||
return author_str | return author_str | ||||
ardumont: I see that you are consistent with the other conditional.
Still, out of curiosity, what's the… | |||||
Done Inline ActionsI could have used isinstance indeed but as no type inheritance is implied here but only base Python types check, simply using type does also the job. anlambert: I could have used `isinstance` indeed but as no type inheritance is implied here but only base… | |||||
elif type(author_data) is list: | |||||
return author_data[0] if len(author_data) > 0 else '' | |||||
else: | else: | ||||
return author_data | return author_data | ||||
author_data = {} | author_data = {} | ||||
if 'author' in package_json: | if 'author' in package_json: | ||||
author_str = _author_str(package_json['author']) | author_str = _author_str(package_json['author']) | ||||
author_data = parse_npm_package_author(author_str) | author_data = parse_npm_package_author(author_str) | ||||
elif 'authors' in package_json and len(package_json['authors']) > 0: | elif 'authors' in package_json and len(package_json['authors']) > 0: | ||||
Show All 26 Lines |
I see that you are consistent with the other conditional.
Still, out of curiosity, what's the difference with isinstance(author, list)?
I checked [1] to have a feel of it ;)
[1] https://stackoverflow.com/questions/1549801/what-are-the-differences-between-type-and-isinstance