-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: Support transient identities and traits #93
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a0df5e6
feat: Support transient identities and traits
khvn26 908ad80
formatting
khvn26 a1517ff
formatting?
khvn26 558d70f
remove linting from GHA
khvn26 0a5f0e5
formatting!!!
khvn26 f38df63
naming
khvn26 35e456d
fix
khvn26 a8126ac
naming
khvn26 69d5769
fix tests
khvn26 b0e85d8
transient_traits -> transient_trait_keys
khvn26 c1027d3
remove redundant dev dependencies
khvn26 d55fa91
improve API, typing
khvn26 0462c21
fix typing for older versions
khvn26 bfdbb42
improve naming
khvn26 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 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 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 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 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 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 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,25 @@ | ||
import typing | ||
|
||
from flag_engine.identities.traits.types import TraitValue | ||
from typing_extensions import TypeAlias | ||
|
||
_JsonScalarType: TypeAlias = typing.Union[ | ||
int, | ||
str, | ||
float, | ||
bool, | ||
None, | ||
] | ||
JsonType: TypeAlias = typing.Union[ | ||
_JsonScalarType, | ||
typing.Dict[str, "JsonType"], | ||
typing.List["JsonType"], | ||
] | ||
|
||
|
||
class TraitConfig(typing.TypedDict): | ||
value: TraitValue | ||
transient: bool | ||
|
||
|
||
TraitMapping: TypeAlias = typing.Mapping[str, typing.Union[TraitValue, TraitConfig]] |
This file contains 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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import typing | ||
|
||
from flag_engine.identities.traits.types import TraitValue | ||
from flagsmith.types import JsonType, TraitMapping | ||
|
||
Identity = typing.TypedDict( | ||
"Identity", | ||
{"identifier": str, "traits": typing.List[typing.Mapping[str, TraitValue]]}, | ||
) | ||
|
||
|
||
def generate_identities_data( | ||
identifier: str, traits: typing.Optional[typing.Mapping[str, TraitValue]] = None | ||
) -> Identity: | ||
return { | ||
"identifier": identifier, | ||
"traits": ( | ||
[{"trait_key": k, "trait_value": v} for k, v in traits.items()] | ||
if traits | ||
else [] | ||
), | ||
} | ||
def generate_identity_data( | ||
identifier: str, | ||
traits: TraitMapping, | ||
*, | ||
transient: bool, | ||
) -> JsonType: | ||
identity_data: typing.Dict[str, JsonType] = {"identifier": identifier} | ||
traits_data: typing.List[JsonType] = [] | ||
for trait_key, trait_value in traits.items(): | ||
trait_data: typing.Dict[str, JsonType] = {"trait_key": trait_key} | ||
if isinstance(trait_value, dict): | ||
trait_data["trait_value"] = trait_value["value"] | ||
if trait_value.get("transient"): | ||
trait_data["transient"] = True | ||
else: | ||
trait_data["trait_value"] = trait_value | ||
traits_data.append(trait_data) | ||
identity_data["traits"] = traits_data | ||
if transient: | ||
identity_data["transient"] = True | ||
return identity_data |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return type be
JsonType
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type here corresponds to
response.json()
type, which istyping.Any
.Casting to a specific type is responsibility of the caller, see e.g.
flagsmith-python-client/flagsmith/flagsmith.py
Lines 358 to 359 in b0e85d8