A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pydantic/pydantic/issues/2323 below:

Mapping types are coerced to dict · Issue #2323 · pydantic/pydantic · GitHub

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.5.1
            pydantic compiled: True
                 install path: C:\Users\ofek\AppData\Local\Programs\Python\Python38\Lib\site-packages\pydantic
               python version: 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
                     platform: Windows-10-10.0.19041-SP0
     optional deps. installed: ['typing-extensions', 'email-validator']

I'm trying to use https://github.com/MagicStack/immutables

from __future__ import annotations

from typing import Mapping

from immutables import Map
from pydantic import BaseModel


class Model(BaseModel):
    test: Mapping[str, int]

print(type(Model(test=Map(key=42)).test))

produces

Is there a way to keep the type of encountered Mappings, or create a type representing immutables.Map?

I've been at this for hours reading docs/closed issues, trying various approaches, and now I'm simply at a loss here.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4