Skip to content

refactor: type hints private interface #389

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 13 commits into from
Jul 12, 2022

Conversation

andrewleap-optimizely
Copy link
Contributor

Summary

  • Add type hints to the private interface of SDK.
  • Enable strict type checking, enforcing type signatures going forward (except on unit tests).

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address.

blocking_timeout: Optional[int] = None,
url: Optional[str] = None,
url_template: Optional[str] = None,
logger: Optional[optimizely_logger.Logger] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, is the type in the past we were expecting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a type alias for the union of the python standard library logging.Logger and our BaseLogger.

variables: Optional[dict[str, Any]] = None,
rule_key: Optional[str] = None,
flag_key: Optional[str] = None,
user_context: Optional[OptimizelyUserContext] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with removing the user_context default None, is that we can't have a non default argument after default arguments. So to remove the user_context default, we would need to make user_context the first parameter or remove all preceding defaults, which would both be breaking changes.

@@ -16,21 +16,21 @@

https://pypi.python.org/pypi/mmh3/2.3.1
'''
from __future__ import annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am leaving this file unreviewed.

@@ -624,7 +629,7 @@ def get_variation(

return variation_key

def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optional[dict[str, Any]] = None) -> bool:
def is_feature_enabled(self, feature_key: str, user_id: str, attributes: Optional[UserAttributes] = None) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please confirm, this won't break any code change.

Copy link
Contributor Author

@andrewleap-optimizely andrewleap-optimizely Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially a no-op wrapper, that gives it a name for the type checker to track. But at runtime the behavior is unchanged.

https://docs.python.org/3/library/typing.html#distinct

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@Mat001 Mat001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Hope I didn't miss anything, I went through most of it before.

@andrewleap-optimizely andrewleap-optimizely merged commit f539d7d into master Jul 12, 2022
@andrewleap-optimizely andrewleap-optimizely deleted the aleap/type_hints_private_interface branch July 12, 2022 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants