Repository: hikari-py/hikari
Pull request #1951 (2024-06-30 14:06:21)

Add `display_name` to `PartialUser`
### Checklist
- [x] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.

### Related issues
None



Patch:
diff --git a/changes/1951.feature.md b/changes/1951.feature.md
new file mode 100644
index 00000000..c82a655d
--- /dev/null
+++ b/changes/1951.feature.md
@@ -0,0 +1,1 @@
+Add `display_name` to `PartialUser`
diff --git a/dev-requirements/flake8.txt b/dev-requirements/flake8.txt
index ab8d8d0a..85791c1c 100644
--- a/dev-requirements/flake8.txt
+++ b/dev-requirements/flake8.txt
@@ -7,7 +7,7 @@ flake8-bandit~=4.1.1                    # runs bandit
 flake8-black==0.3.6                     # runs black
 flake8-builtins==2.5.0                  # builtin shadowing checks
 flake8-coding==1.3.2                    # coding magic-comment detection
-flake8-comprehensions==3.14.0           # comprehension checks
+flake8-comprehensions==3.15.0           # comprehension checks
 flake8-docstrings==1.7.0                # pydocstyle support
 flake8-executable==2.1.3                # shebangs
 flake8-fixme==1.1.1                     # "fix me" counter
diff --git a/dev-requirements/mkdocs.txt b/dev-requirements/mkdocs.txt
index 1e922062..00af2173 100644
--- a/dev-requirements/mkdocs.txt
+++ b/dev-requirements/mkdocs.txt
@@ -1,7 +1,7 @@
 mkdocs==1.6.0
 
 # Mkdocs Material
-mkdocs-material[imaging]==9.5.27
+mkdocs-material[imaging]==9.5.28
 
 # Docstring parsing for API reference
 mkdocstrings[python]==0.25.1
diff --git a/dev-requirements/pyright.txt b/dev-requirements/pyright.txt
index 27c9148f..31134125 100644
--- a/dev-requirements/pyright.txt
+++ b/dev-requirements/pyright.txt
@@ -1,1 +1,1 @@
-pyright==1.1.369
+pyright==1.1.370
diff --git a/dev-requirements/release.txt b/dev-requirements/release.txt
index b084f74b..cd50e5e1 100644
--- a/dev-requirements/release.txt
+++ b/dev-requirements/release.txt
@@ -1,3 +1,3 @@
-twine==5.1.0
+twine==5.1.1
 
 -r build.txt
diff --git a/hikari/users.py b/hikari/users.py
index e702dc4a..2ec1bb3d 100644
--- a/hikari/users.py
+++ b/hikari/users.py
@@ -184,6 +184,14 @@ def username(self) -> undefined.UndefinedOr[str]:
     def global_name(self) -> undefined.UndefinedNoneOr[str]:
         """Global name for the user, if they have one, otherwise [`None`][]."""
 
+    @property
+    def display_name(self) -> undefined.UndefinedNoneOr[str]:
+        """Return the user's display name.
+
+        Either users global name (if set) or its username.
+        """
+        return self.global_name or self.username
+
     @property
     @abc.abstractmethod
     def is_bot(self) -> undefined.UndefinedOr[bool]:


Test patch:
diff --git a/tests/hikari/test_users.py b/tests/hikari/test_users.py
index 90fd24bf..b7c00031 100644
--- a/tests/hikari/test_users.py
+++ b/tests/hikari/test_users.py
@@ -344,6 +344,14 @@ def test_str_operator_when_partial(self, obj):
     def test_mention_property(self, obj):
         assert obj.mention == "<@123>"
 
+    def test_display_name_property_when_global_name(self, obj):
+        obj.global_name = "Thommo"
+        assert obj.display_name == obj.global_name
+
+    def test_display_name_property_when_no_global_name(self, obj):
+        obj.global_name = None
+        assert obj.display_name == obj.username
+
     @pytest.mark.asyncio
     async def test_fetch_self(self, obj):
         user = object()