PyGithub / PyGithub/PyGithub

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

Open Beginner friendly
#3,553 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
1.9k
Avg merge
17m
Merged PRs (30d)
2

Description

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
@property
def merged_by(self) -> NamedUser:
    self._completeIfNotSet(self._merged_by)
    return self._merged_by.value

Expected type annotation

@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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in PullRequest.py at the merged_by property around line 367, and compare its annotation with the GitHub Pull Request object schema linked in the issue. Done means the annotation reflects that the API may return None while preserving the existing property behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.