only_overlap.py 469 B

12345678910111213141516171819202122
  1. from typing import Type, TypeVar
  2. T = TypeVar("T")
  3. def _only_overlap_as_params(x: dict, Params: Type[T]) -> T:
  4. return Params(
  5. **{
  6. key: value
  7. for key, value in x.items()
  8. if key in Params.__annotations__ # type: ignore
  9. }
  10. )
  11. def only_overlap(x: dict, Params: Type[T]) -> T:
  12. return {
  13. key: value
  14. for key, value in x.items()
  15. if key in Params.__required_keys__ # type: ignore
  16. }