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 слични објави

Пребарај: #loans

当前筛选 #loans清除筛选
NIDO Russia (НИДО)

@nido_russia · Post #1907 · 02.12.2024 г., 12:42

Russian government to subsidize rural mortgages 📌The funds are provided for the purchase of housing in rural areas. 📌This was said by the Prime Minister Mikhail Mishustin, at a meeting with Deputy Prime Ministers. 📌Additional 5 billion rubles will be allocated to subsidize over 160 thousand loans (under the Rural Mortgage program) that have been concluded in recent years. 📌In July 2023, the government increased the size of the concessional loan under the "Rural mortgage" to 6 million rubles. The initial payment for the program launched in the spring of 2020 is 20%. 📌 A loan in the amount of 100 thousand to 6 million rubles is issued for a period of up to 25 years. The preferential rate of 3% is preserved. #news#russia#nido_russia#rural#housing#loans https://t.me/nido_russia

Venture Village Wall 🦄

@venturevillagewall · Post #3398 · 18.12.2024 г., 12:10

Svakarma Finance Raises $10.4M Svakarma Finance successfully raised $10.40 million in funding on December 13, 2024. For more details, visit their website. #Funding#Finance#Svakarma#Investment#Capital#Startup #2024 #Market#Growth#Innovations#Loans#FinanceTech#DigitalFinance#Fintech#VentureCapital#Equity#FundingRound#FinancialServices#Economy

Venture Village Wall 🦄

@venturevillagewall · Post #3423 · 18.12.2024 г., 12:11

VakıfBank Secures $870M Funding Round VakıfBank has announced a funding round of $870 million, set for November 26, 2024. For more details, visit their official page here. #Funding#VakıfBank#Finance#Investment#FundingRound#Banking#Loans#Capital#Turkey#Business#Economy#November2024#Growth#Market#Assets#InvestmentOpportunities#FinancialServices#InstitutionalInvestors#Debt#Equity

Venture Village Wall 🦄

@venturevillagewall · Post #4071 · 05.02.2025 г., 07:00

NBU Accuses BitCapital of Illegal Lending The National Bank of Ukraine (NBU) has accused the Ukrainian service BitCapital, which issues loans in USDT stablecoins, of providing illegal lending services. Over 700 complaints from citizens cite issues like high interest rates, wrongful charges, aggressive debt collection tactics, and lack of transparency. The service's operations in Ukraine are now banned. Read more here #Ukraine#BitCapital#USDT#Banking#Regulation#Lending#Finance#Crypto#NBU#Loans#ConsumerProtection#Debt#InterestRates#Bans#Complaints#Market#IllegalServices#Transparency#FinanceNews#VC#Crypto