#3553·PyGithub

`PullRequest.merged_by` return type should be `NamedUser | None`

Author: niksauerCreated Aug 7, 2026Updated Aug 10, 2026

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.

python
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

python
# PullRequest.py line 367
@property
def merged_by(self) -> NamedUser:
    self._completeIfNotSet(self._merged_by)
    return self._merged_by.value

Expected type annotation

python
@property
def merged_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