-
Notifications
You must be signed in to change notification settings - Fork 30
fix: fix type hints of EvaluationContext and HookHints #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,4 @@ repos: | |
| rev: v1.18.1 | ||
| hooks: | ||
| - id: mypy | ||
| files: openfeature | ||
| files: openfeature|tests/typechecking | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Type Checking Tests | ||
|
|
||
| This directory contains type checking validation files that are designed to be checked by **type checkers only**, not executed by pytest. | ||
|
|
||
| ## Purpose | ||
|
|
||
| These files validate that the type annotations work correctly through static analysis. | ||
| They ensure type safety for complex type definitions like `EvaluationContextAttribute` and other typed interfaces. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Requirement 3.1.2""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from openfeature.evaluation_context import EvaluationContext | ||
|
|
||
| # positive | ||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"bool": True}, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"int": 42}, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"float": 3.14}, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"str": "value"}, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"date": datetime.now()}, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={ | ||
| "bool_list": [True, False], | ||
| "int_list": [1, 2], | ||
| "float_list": [1.1, 2.2], | ||
| "date_list": [datetime.now(), datetime.now()], | ||
| "str_list": ["a", "b"], | ||
| "list_list": [ | ||
| ["a", "b"], | ||
| ["c", "d"], | ||
| ], | ||
| "dict_list": [ | ||
| {"int": 42}, | ||
| {"str": "value"}, | ||
| ], | ||
| }, | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={ | ||
| "user": { | ||
| "id": 12345, | ||
| "name": "John Doe", | ||
| "active": True, | ||
| "last_login": datetime.now(), | ||
| "permissions": ["read", "write", "admin"], | ||
| "metadata": { | ||
| "source": "api", | ||
| "version": 2.1, | ||
| "tags": ["premium", "beta"], | ||
| "config": { | ||
| "nested_deeply": [ | ||
| {"item": 1, "enabled": True}, | ||
| {"item": 2, "enabled": False}, | ||
| ] | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| # negative | ||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"null": None}, # type: ignore[dict-item] | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={"complex": -4.5j}, # type: ignore[dict-item] | ||
| ) | ||
|
|
||
| EvaluationContext( | ||
| targeting_key="key", | ||
| attributes={42: 42}, # type: ignore[dict-item] | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """Requirement 4.6.1""" | ||
|
|
||
| from openfeature.hook import HookData | ||
|
|
||
| # positive | ||
| any_hook_data: HookData = { | ||
| "user": { | ||
| "id": 12345, | ||
| "name": "John Doe", | ||
| "active": True, | ||
| "permissions": ["read", "write", "admin"], | ||
| "metadata": { | ||
| "source": "api", | ||
| "version": 2.1, | ||
| "tags": ["premium", "beta"], | ||
| "config": { | ||
| "nested_deeply": [ | ||
| {"item": 1, "enabled": True}, | ||
| {"item": 2, "enabled": False}, | ||
| ] | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| class ExampleClass: | ||
| pass | ||
|
|
||
|
|
||
| class_hook_data: HookData = {"example": ExampleClass} | ||
|
|
||
| # negative | ||
| int_key_hook_data: HookData = {42: 42} # type: ignore[dict-item] | ||
gruebel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Requirement 4.1.2""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from openfeature.hook import HookHints | ||
|
|
||
| # positive | ||
| bool_hook_hint: HookHints = {"bool": True} | ||
|
|
||
| int_hook_hint: HookHints = {"int": 42} | ||
|
|
||
| float_hook_hint: HookHints = {"float": 3.14} | ||
|
|
||
| str_hook_hint: HookHints = {"str": "value"} | ||
|
|
||
| date_hook_hint: HookHints = {"date": datetime.now()} | ||
|
|
||
| list_hook_hint: HookHints = { | ||
| "bool_list": [True, False], | ||
| "int_list": [1, 2], | ||
| "float_list": [1.1, 2.2], | ||
| "date_list": [datetime.now(), datetime.now()], | ||
| "str_list": ["a", "b"], | ||
| "list_list": [ | ||
| ["a", "b"], | ||
| ["c", "d"], | ||
| ], | ||
| "dict_list": [ | ||
| {"int": 42}, | ||
| {"str": "value"}, | ||
| ], | ||
| } | ||
|
|
||
| dict_hook_hint: HookHints = { | ||
| "user": { | ||
| "id": 12345, | ||
| "name": "John Doe", | ||
| "active": True, | ||
| "last_login": datetime.now(), | ||
| "permissions": ["read", "write", "admin"], | ||
| "metadata": { | ||
| "source": "api", | ||
| "version": 2.1, | ||
| "tags": ["premium", "beta"], | ||
| "config": { | ||
| "nested_deeply": [ | ||
| {"item": 1, "enabled": True}, | ||
| {"item": 2, "enabled": False}, | ||
| ] | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| # negative | ||
| null_hook_hint: HookHints = {"null": None} # type: ignore[dict-item] | ||
|
|
||
| complex_hook_hint: HookHints = {"complex": -4.5j} # type: ignore[dict-item] | ||
|
|
||
| int_key_hook_hint: HookHints = {42: 42} # type: ignore[dict-item] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.