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

Резултати

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

Пребарај: #gst

当前筛选 #gst清除筛选
gov.sg

@Govsg · Post #1890 · 31.12.2023 г., 06:13

With the #GST rate change on 1 Jan 2024, here are some scenarios you may find yourself in. 👉🏻 Swipe to find out how the rate change affects your ongoing or upcoming transactions. 📷: @irassg More info here: go.gov.sg/GSTratechange2024

Hashtags

겁나빠른 경제 전문 - 뉴스 드리고

@dreago_news_ch · Post #262916 · 13.05.2026 г., 08:12

🔔 GST 주가, 5월 13일 66,500원 4.40% 상승 마감 📈#GST 📝#코스닥#증권 주요 주가 상승이 확인되었으나, PER이 업종 평균보다 낮아 추가 상승 여력이 다소 제한적일 수 있습니다. ⬜⬜⬜⬜⬜│🟥⬜⬜⬜⬜ 【 겁나빠른 #드리고봇 뉴스 】 https://www.topstarnews.net/news/articleView.html?idxno=16059597

IRAS

@irassg · Post #725 · 22.12.2023 г., 06:30

Navigate the right GST rate to pay for transactions spanning the rate change with new mummy and her bestie! 💁‍♀️💡 A transaction is considered to span the GST rate change if one or two of the following events takes place wholly or partially on/after 1 Jan 2024: - The issuance of invoice by supplier - The receipt of payment by supplier - The delivery of goods or performance of services More info at go.gov.sg/irasgst-rc-consumers #GST#GSTRateChange#skit#iras#irassg

IRAS

@irassg · Post #723 · 20.12.2023 г., 09:10

🎵 We carry through, do what we need to do~ Yes, I’m a GST-registered business just like you 🎵 Here are 3 key things GST-registered businesses need to prepare for the 2024 GST rate change: 1) Update systems to incorporate 9% GST from 1 Jan 2024 2) Prepare price displays to reflect 9% GST from 1 Jan 2024 3) Understand transitional rules to apply the correct GST rate for transactions spanning 1 Jan 2024 Learn more at go.gov.sg/irasgst-rc-businesses #GST#GSTRateChange#iamjustlikeyou#iras#irassg