From 93137b2304c363ab784993e0e69d505d32a4664c Mon Sep 17 00:00:00 2001 From: Lucas Hardt Date: Sun, 22 Dec 2024 12:27:47 +0100 Subject: [PATCH 1/2] Make VariantBean.gender optional Remove CustomGender.UNKNOWN --- docs/changelog.rst | 7 ++++++- fortnite_api/cosmetics/variants/bean.py | 8 +++++--- fortnite_api/enums.py | 3 --- tests/test_async_methods.py | 5 ++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 96da6c27..006f32df 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,11 @@ Changelog v3.3.0 ------- +Breaking Changes +~~~~~~~~~~~~~~~~ +- If :attr:`fortnite_api.VariantBean.gender` isn't present, it's now ``None``, instead of ``CustomGender.UNKNOWN``. +- ``CustomGender.UNKNOWN`` has been removed, hence it's not used anymore. + Bug Fixes ~~~~~~~~~ - Fixed an issue that caused :class:`fortnite_api.Asset.resize` to raise :class:`TypeError` instead of :class:`ValueError` when the given size isn't a power of 2. @@ -23,7 +28,7 @@ v3.2.1 Bug Fixes ~~~~~~~~~ -- Fixed an issue due a change from Epic that causes :class:`fortnite_api.VariantBean` to not have a :class:`fortnite_api.CustomGender`. It now uses :attr:`fortnite_api.CustomGender.UNKNOWN` in such case instead of raising an exception. +- Fixed an issue due a change from Epic that causes :class:`fortnite_api.VariantBean` to not have a :class:`fortnite_api.CustomGender`. It now uses ``CustomGender.UNKNOWN`` in such case instead of raising an exception. - Fixed typo within fallback system for :class:`fortnite_api.TileSize` as ``raise`` keyword was used instead of ``return``. - Fixed an issue that caused a :class:`KeyError` to be raised when using :meth:`fortnite_api.Client.search_br_cosmetics` or :meth:`fortnite_api.SyncClient.search_br_cosmetics` without ``multiple`` parameter. diff --git a/fortnite_api/cosmetics/variants/bean.py b/fortnite_api/cosmetics/variants/bean.py index aa428579..4a0a7762 100644 --- a/fortnite_api/cosmetics/variants/bean.py +++ b/fortnite_api/cosmetics/variants/bean.py @@ -55,8 +55,8 @@ class VariantBean(Cosmetic[dict[str, Any], HTTPClientT]): The ID of the cosmetic that this bean represents, if any. name: :class:`str` The name of this bean. - gender: :class:`fortnite_api.CustomGender` - Denotes the gender of this bean. + gender: Optional[:class:`fortnite_api.CustomGender`] + Denotes the gender of this bean. Can be ``None`` if no gender is assigned. gameplay_tags: List[:class:`str`] The gameplay tags associated with this bean. @@ -76,7 +76,9 @@ def __init__(self, *, data: dict[str, Any], http: HTTPClientT) -> None: self.cosmetic_id: Optional[str] = data.get('cosmetic_id') self.name: str = data['name'] - self.gender: CustomGender = try_enum(CustomGender, data['gender'] if 'gender' in data else 'Unknown') + + _gender = data.get("gender") + self.gender: Optional[CustomGender] = _gender and try_enum(CustomGender, _gender) self.gameplay_tags: list[str] = get_with_fallback(data, 'gameplay_tags', list) _images = data.get('images') diff --git a/fortnite_api/enums.py b/fortnite_api/enums.py index 1c6422c6..c7a0607e 100644 --- a/fortnite_api/enums.py +++ b/fortnite_api/enums.py @@ -539,13 +539,10 @@ class CustomGender(Enum): A female character. MALE A male character. - UNKNOWN - The character's gender is unknown. """ FEMALE = 'EFortCustomGender::Female' MALE = 'EFortCustomGender::Male' - UNKNOWN = 'Unknown' class ProductTag(Enum): diff --git a/tests/test_async_methods.py b/tests/test_async_methods.py index 02cf0e5a..de0ed5d1 100644 --- a/tests/test_async_methods.py +++ b/tests/test_async_methods.py @@ -344,7 +344,10 @@ async def test_async_fetch_variants_beans(api_key: str, response_flags: fn_api.R def _test_variant_bean(variant: fn_api.VariantBean[Any]): assert isinstance(variant, fn_api.VariantBean) assert variant.name - assert isinstance(variant.gender, fn_api.CustomGender) + + gender = variant.gender + if gender: + assert isinstance(gender, fn_api.CustomGender) images = variant.images if images: From 1bf1c8326d1f51ae32f6c7d0c38836f277d80995 Mon Sep 17 00:00:00 2001 From: Lucas Hardt Date: Sun, 9 Nov 2025 14:00:36 +0100 Subject: [PATCH 2/2] update tests for changed gender --- tests/cosmetics/cosmetic_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cosmetics/cosmetic_utils.py b/tests/cosmetics/cosmetic_utils.py index f100e8e5..5f926762 100644 --- a/tests/cosmetics/cosmetic_utils.py +++ b/tests/cosmetics/cosmetic_utils.py @@ -177,7 +177,10 @@ def validate_variant_lego(variant: fortnite_api.VariantLego[Any]): def validate_variant_bean(variant: fortnite_api.VariantBean[Any]): assert isinstance(variant, fortnite_api.VariantBean) assert variant.name - assert isinstance(variant.gender, fortnite_api.CustomGender) + + gender = variant.gender + if gender: + assert isinstance(gender, fortnite_api.CustomGender) images = variant.images if images: