Skip to content

Commit 4cb6e8c

Browse files
committed
Fix author duplication bug with NamedTuples
1 parent de9ab25 commit 4cb6e8c

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

pep_sphinx_extensions/pep_zero_generator/author.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def parse_author_email(author_email_tuple: tuple[str, str], authors_overrides: d
3737
# Add an escape to avoid docutils turning `v.` into `22.`.
3838
name_parts.surname = f"\\{name_parts.surname}"
3939

40-
if name_parts.suffix is not None:
40+
if name_parts.suffix:
4141
last_first = f"{name_parts.surname}, {name_parts.forename}, {name_parts.suffix}"
4242
return Author(last_first, name_parts.surname, email)
4343

pep_sphinx_extensions/pep_zero_generator/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def details(self, *, title_length) -> dict[str, str | int]:
107107
# how the status should be represented in the index
108108
"status": " " if self.status in HIDE_STATUS else self.status[0].upper(),
109109
# the author list as a comma-separated with only last names
110-
"authors": ", ".join(x.nick for x in self.authors),
110+
"authors": ", ".join(author.nick for author in self.authors),
111111
}
112112

113113

pep_sphinx_extensions/pep_zero_generator/writer.py

+24-25
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
from pep_sphinx_extensions.pep_zero_generator.errors import PEPError
2525

2626
if TYPE_CHECKING:
27-
from pep_sphinx_extensions.pep_zero_generator.author import Author
28-
from pep_sphinx_extensions.pep_zero_generator.parser import PEP
27+
from pep_sphinx_extensions.pep_zero_generator.parser import PEP
2928

3029
title_length = 55
3130
author_length = 40
@@ -195,15 +194,15 @@ def write_pep0(self, peps: list[PEP]):
195194

196195
# PEP owners
197196
authors_dict = _verify_email_addresses(peps)
198-
max_name_len = max(len(author.last_first) for author in authors_dict.keys())
197+
max_name_len = max(len(author_name) for author_name in authors_dict)
199198
self.emit_title("Authors/Owners", "authors")
200199
self.emit_author_table_separator(max_name_len)
201200
self.emit_text(f"{'Name':{max_name_len}} Email Address")
202201
self.emit_author_table_separator(max_name_len)
203-
for author in _sort_authors(authors_dict):
202+
for author_name in _sort_authors(authors_dict):
204203
# Use the email from authors_dict instead of the one from "author" as
205204
# the author instance may have an empty email.
206-
self.emit_text(f"{author.last_first:{max_name_len}} {authors_dict[author]}")
205+
self.emit_text(f"{author_name:{max_name_len}} {authors_dict[author_name]}")
207206
self.emit_author_table_separator(max_name_len)
208207
self.emit_newline()
209208
self.emit_newline()
@@ -268,27 +267,27 @@ def _classify_peps(peps: list[PEP]) -> tuple[list[PEP], ...]:
268267
return meta, info, provisional, accepted, open_, finished, historical, deferred, dead
269268

270269

271-
def _verify_email_addresses(peps: list[PEP]) -> dict[Author, str]:
272-
authors_dict: dict[Author, set[str]] = {}
270+
def _verify_email_addresses(peps: list[PEP]) -> dict[str, str]:
271+
authors_dict: dict[str, set[str]] = {}
273272
for pep in peps:
274273
for author in pep.authors:
275274
# If this is the first time we have come across an author, add them.
276-
if author not in authors_dict:
277-
authors_dict[author] = {author.email} if author.email else set()
278-
else:
279-
# If the new email is an empty string, move on.
280-
if not author.email:
281-
continue
282-
# If the email has not been seen, add it to the list.
283-
authors_dict[author].add(author.email)
284-
285-
valid_authors_dict = {}
286-
too_many_emails = []
287-
for author, emails in authors_dict.items():
275+
if author.last_first not in authors_dict:
276+
authors_dict[author.last_first] = set()
277+
278+
# If the new email is an empty string, move on.
279+
if not author.email:
280+
continue
281+
# If the email has not been seen, add it to the list.
282+
authors_dict[author.last_first].add(author.email)
283+
284+
valid_authors_dict: dict[str, str] = {}
285+
too_many_emails: list[tuple[str, set[str]]] = []
286+
for last_first, emails in authors_dict.items():
288287
if len(emails) > 1:
289-
too_many_emails.append((author.last_first, emails))
288+
too_many_emails.append((last_first, emails))
290289
else:
291-
valid_authors_dict[author] = next(iter(emails), "")
290+
valid_authors_dict[last_first] = next(iter(emails), "")
292291
if too_many_emails:
293292
err_output = []
294293
for author, emails in too_many_emails:
@@ -301,13 +300,13 @@ def _verify_email_addresses(peps: list[PEP]) -> dict[Author, str]:
301300
return valid_authors_dict
302301

303302

304-
def _sort_authors(authors_dict: dict[Author, str]) -> list[Author]:
305-
return sorted(authors_dict.keys(), key=_author_sort_by)
303+
def _sort_authors(authors_dict: dict[str, str]) -> list[str]:
304+
return sorted(authors_dict, key=_author_sort_by)
306305

307306

308-
def _author_sort_by(author: Author) -> str:
307+
def _author_sort_by(author_name: str) -> str:
309308
"""Skip lower-cased words in surname when sorting."""
310-
surname, *_ = author.last_first.split(",")
309+
surname, *_ = author_name.split(",")
311310
surname_parts = surname.split()
312311
for i, part in enumerate(surname_parts):
313312
if part[0].isupper():

0 commit comments

Comments
 (0)