From 1d6d5d72f8c9fab2f91f87aeef0d4aef17a8ee6a Mon Sep 17 00:00:00 2001 From: Mattia Succurro Date: Wed, 18 Jun 2025 09:35:09 +0200 Subject: [PATCH] fix Snowflake.to_b32l() for negative values --- src/suou/__init__.py | 2 +- src/suou/snowflake.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/suou/__init__.py b/src/suou/__init__.py index b56f3eb..9b2f722 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -27,7 +27,7 @@ from .itertools import makelist, kwargs_prefix, ltuple, rtuple, additem from .i18n import I18n, JsonI18n, TomlI18n from .snowflake import Snowflake, SnowflakeGen -__version__ = "0.3.0" +__version__ = "0.3.1" __all__ = ( 'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase', diff --git a/src/suou/snowflake.py b/src/suou/snowflake.py index e9f2708..06ea85e 100644 --- a/src/suou/snowflake.py +++ b/src/suou/snowflake.py @@ -131,7 +131,9 @@ class Snowflake(int): def to_oct(self) -> str: return f'{self:o}' def to_b32l(self) -> str: - """PSA Snowflake Base32 representations are padded to 10 bytes!""" + # PSA Snowflake Base32 representations are padded to 10 bytes! + if self < 0: + return '_' + Snowflake.to_b32l(-self) return b32lencode(self.to_bytes(10, 'big')).lstrip('a') @classmethod