#Is there a convenient way to express "the type of my primary keys"?

7 messages · Page 1 of 1 (latest)

lyric summit
#

In my current project, my models all default to BigAuto for their primary keys. I have lots of functions that take primary keys as arguments, and that use type hinting; they look like

def channel_name_from_player_pks(pk1: int, pk2: int):

That's fine, but I dread the day when I decide to switch to UUIDs or something for my primary keys, and I'll have to update a zillion function signatures.

So I'm hoping there's some way I can add another level of indirection. I'll probably put something like

PK = it
``` in some globally-available module, and change the signatures to look like 
```py
def channel_name_from_player_pks(pk1: PK, pk2: PK):
```, but this feels kind of klunky.  

Has anyone else solved this problem more elegantly?
tidal violet
#
type PK = int
lyric summit
#

yep

#

now I have to import it in all the modules that use it, but ... 🤷

lyric summit
#

Thanks @tidal violet