Problem
PullRequest.merged_by is typed as returning NamedUser, but the GitHub API can return null for this field on merged pull requests. This causes an AttributeError at runtime when accessing .login or other attributes on the result.
pr=repo.get_pull(123)
print(pr.merged_by.login) # AttributeError: 'NoneType' object has no attribute 'login'
When does this happen?
merged_by is null when a PR is implicitly merged — i.e., someone pushes the PR's commits directly to the base branch (e.g., git push to main) rather than using GitHub's merge button. GitHub detects the commits are now in the base branch and closes the PR as "merged," but since no one clicked the merge button, there is no merged_by user.
This also shows up in webhook payloads (pull_request event with action: closed and merged: true), where the merged_by field is null.
Current type annotation
# PullRequest.py line 367@propertydefmerged_by(self) ->NamedUser:
self._completeIfNotSet(self._merged_by)
returnself._merged_by.value
Expected type annotation
@propertydefmerged_by(self) ->NamedUser|None:
...
This is consistent with how the GitHub REST API documents the field — the Pull Request object schema shows merged_by as nullable.
Version
PyGithub 2.9.1, Python 3.13
Problem
PullRequest.merged_byis typed as returningNamedUser, but the GitHub API can returnnullfor this field on merged pull requests. This causes anAttributeErrorat runtime when accessing.loginor other attributes on the result.When does this happen?
merged_byisnullwhen a PR is implicitly merged — i.e., someone pushes the PR's commits directly to the base branch (e.g.,git pushtomain) rather than using GitHub's merge button. GitHub detects the commits are now in the base branch and closes the PR as "merged," but since no one clicked the merge button, there is nomerged_byuser.This also shows up in webhook payloads (
pull_requestevent withaction: closedandmerged: true), where themerged_byfield isnull.Current type annotation
Expected type annotation
This is consistent with how the GitHub REST API documents the field — the Pull Request object schema shows
merged_byas nullable.Version
PyGithub 2.9.1, Python 3.13