TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 4 слични објави

Пребарај: #futo

当前筛选 #futo清除筛选
Libreware

@libreware · Post #1455 · 03.05.2025 г., 22:27

#FUTO#Keyboard Updates: The Swipe Dataset is Public! https://peertube.futo.org/videos/watch/44d2e41a-307b-49ab-9a14-1e2e1eaa9a94 You can access the dataset here: https://huggingface.co/datasets/futo-org/swipe.futo.org More info about FUTO Keyboard https://t.me/Libreware/1299 You can learn more about FUTO here: https://futo.org

Libreware

@libreware · Post #1452 · 03.05.2025 г., 11:47

FUTO is launching a new open-source software distribution project: the FUTOcore Software Store. https://www.bitchute.com/video/dVmDId8GPn8b/ You can learn more about FUTOcore and participate in our survey here: https://futocore.futo.org/ This talk was given by Adam Jesionowski on March 15 during FUTO's Don't be Evil Conference #futo#apk#store

Libreware

@libreware · Post #1299 · 29.06.2024 г., 08:35

FUTO Keyboard Keyboard being developed, forked from the AOSP keyboard. The goal is to create a good, customizable keyboard that doesn't sacrifice on privacy or freedoms. If you're testing this, please join either the Discord server or the FUTO chat. Your feedback is valuable during this testing period https://keyboard.futo.org https://gitlab.futo.org/alex/keyboard-wiki/-/wikis/FUTO-Keyboard https://github.com/futo-org/android-keyboard/issues https://app.futo.org/fdroid/repo?fingerprint=39D47869D29CBFCE4691D9F7E6946A7B6D7E6FF4883497E6E675744ECDFA6D6D Solving #Google's #Keyboard Privacy Issue: Introducing Offline #voice to text & #keyboard from #FUTO https://odysee.com/solving-google's-keyboard-privacy-issue#7b51783c3bb27a967223ac3a7c3eb756267b1594 https://github.com/abb128/LiveCaptions https://www.nytimes.com/2022/08/21/technology/google-surveillance-toddler-photo.html https://youtu.be/r09Hm2zd2lY https://www.youtube.com/watch?v=_vWAF13KigI 👉 Rossmann chat: https://matrix.to/#/#rossmannrepair:matrix.org #futo#android#keyboard

Libreware

@libreware · Post #1312 · 29.07.2024 г., 14:12

Harbor Decentralized p2p identity verification system. Identity management application written, targeting iOS, and Android, built on Polycentric. Create pseudonymous identities, make claims, link identities across applications. Checkout harbor.social, or docs.polycentric.io for more information What is Harbor and How it Works: https://peertube.futo.org/w/939a212d-920f-4411-b9b6-d60aa4ef4db7 https://gitlab.futo.org/polycentric/harbor/ #p2p#id#verification#futo