Skip to content

PullRequest.merged_by return type should be NamedUser | None #3553

Description

@niksauer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions