Skip to content

Invalid type alias for EvaluationContextAttributes #532

@AlexandrePicosson

Description

@AlexandrePicosson

Hi, I'm trying out OpenFeature and reading the documentation I thought that the following would be a valid evaluation context attribute:

from openfeature.evaluation_context import EvaluationContext

evaluation_context = EvaluationContext(
    targeting_key="my_user_id", attributes={"user_attributes": {"age_category": "30-40"}}
)

However Mypy reports the following error with this code:

$ uv run mypy openfeature.py --install-types --non-interactive --show-traceback
openfeature.py:4: error: Dict entry 0 has incompatible type "str": "str"; expected "str": "Mapping[str, bool | int | float | str | datetime | Sequence[EvaluationContextAttributes] | Mapping[str, EvaluationContextAttributes]]"  [dict-item]

I'm wondering whether this is intentional or it was a mistake when adding stricter type hints in #504.
The following line makes me think this is an error as EvaluationContextAttributes is already a mapping the type accept recursive mappings of mappings that can be matched only with an empty dict and it should be replaced with "EvaluationContextAttributes" to accept structures like dict[str, dict[str: bool | int | float | str | datetime | Sequence[...] | dict[...]].

typing.Mapping[str, "EvaluationContextAttributes"],

If this is really an issue and not an error on my side I would be happy to contribute the fix.


Versions:

  • Python: 3.12.7
  • openfeature-sdk: 0.8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions