Skip to content

Mind inheritance when inferring TypedDict-based class #2876

@Melevir

Description

@Melevir

This one continues #2872.

Here is a reproducible example:

from typing import TypedDict, List
from hypothesis import given, strategies as st

class SomeData(TypedDict):
    a: str
    b: int

class SomeMoreData(SomeData):
    c: List[int]

st.register_type_strategy(
    SomeData, st.builds(SomeData, a=st.just("string from strategy"), b=st.just(42))
)

@given(st.from_type(SomeMoreData))
def test_some_data(item):
    assert item["a"] == "string from strategy"
    assert item["b"] == 42

class EvenMoreData(SomeMoreData):
    b: bool  # tricky case - should *not* use SomeData strategy for this

print(SomeData.__annotations__)
print(SomeMoreData.__annotations__)
print(EvenMoreData.__annotations__)

For now, the test will fail, but it make sense to mind inheritance when inferring TypedDicts types.

If the proposition (or bug, whatever) is approved, I'll try to implement the thing.

Metadata

Metadata

Assignees

Labels

enhancementit's not broken, but we want it to be better

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions