akhundmurad / typeid-python Goto Github PK
View Code? Open in Web Editor NEWPython implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
License: MIT License
Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
License: MIT License
Hi, and thanks for this package!
I noticed a couple of inconsistencies in the TypeID class:
@classmethod
def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
suffix_str = _convert_uuid_to_b32(suffix)
return TypeID(suffix=suffix_str, prefix=prefix)
this class method explicitly returns a TypeID
, when it could use cls
, like the from_string
method right above it.
def _convert_b32_to_uuid(b32: str) -> UUID:
return UUID(bytes=bytes(base32.decode(b32)))
I think this utility function should return the customized uuid6.UUID
instead of uuid.UUID
, since the class constructor calls uuid6.uuid7()
. The difference is subtle, but this way the .uuid
property can return incorrect results if you try to access .uuid.time
:
uuid = uuid6.uuid7()
print(uuid.time)
>>> 1712728754957
tid = typeid.TypeID()
print(tid.uuid.time)
>>> 688659269629691542
uuid6.UUID
has an overridden time
property, which checks the version
, and returns super().time
if the version is not 6, 7, or 8.
The utility function could be updated like so:
def _convert_b32_to_uuid(b32: str):
uuid_bytes = bytes(base32.decode(b32))
uuid_int = int.from_bytes(uuid_bytes)
return uuid6.UUID(int=uuid_int, version=7)
I ran into this while playing around with the idea of modifying the uuid6.uuid7
generator function to receive the timestamp part as a parameter, so that I could also create TypeID instances based on some historical timestamp. This'd be a really useful feature when migrating from database-generated sequenced numeric IDs to TypeIDs. Some other ID generation libraries support this.
I can open a PR for these changes if you'd like. Thanks again!
It would be easier to maintain the project for developers who doesn't use VS Code or wants to run liners from cli if you would use pyproject.toml
or .pylintrc
for rules definition instead of the specific .vscode
settings
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.