Skip to content
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

Typing fixes in config.py #307

Merged
merged 1 commit into from
Jun 29, 2023
Merged

Typing fixes in config.py #307

merged 1 commit into from
Jun 29, 2023

Conversation

ProducerMatt
Copy link
Member

No description provided.

@ProducerMatt ProducerMatt added the enhancement New feature or request label Jun 27, 2023
@ProducerMatt ProducerMatt self-assigned this Jun 27, 2023
@@ -32,7 +32,7 @@ def getenv(env_var: str, default: T) -> Union[str, T]:...
@overload
def getenv(env_var: str) -> str:...

def getenv(env_var: str, default: T = NOT_PROVIDED) -> Union[str, T]:
def getenv(env_var: str, default = NOT_PROVIDED) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is inconsistent/not how @overload works. @overloaded function signatures narrow down the return type, given a particular choice of argument types. Annotations on the function implementation itself (without @overload) should be a strict superset of the @overloaded ones. Here, str is a subset of Union[str, T].

Copy link
Collaborator

Choose a reason for hiding this comment

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

could we make 1 function always return 1 type (str in this case) and use a different funcition name for the other types? or what is the benefit of the overload / generics type?

Copy link
Member Author

Choose a reason for hiding this comment

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

@MatthewBaggins originally it was default: T = NOT_PROVIDED, but this raised typing errors saying NOT_PROVIDED was type str, not T. This change fixes that error, with no other errors raised anywhere else in the file. What do you think needs to be different?

Copy link
Member Author

Choose a reason for hiding this comment

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

@MatthewBaggins I'm going to go ahead and merge, let me know if you have an alternative way to do it that doesn't raise errors.

@ProducerMatt ProducerMatt merged commit 07a3a5a into master Jun 29, 2023
@ProducerMatt ProducerMatt deleted the typing-config branch August 13, 2023 23:45
@ProducerMatt ProducerMatt restored the typing-config branch August 13, 2023 23:46
@ProducerMatt ProducerMatt deleted the typing-config branch August 13, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants