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

[pythonic resources][rfc] Adjust EnvVar behavior to allow for direct usage #14488

Closed
wants to merge 1 commit into from

Conversation

benpankow
Copy link
Member

@benpankow benpankow commented May 26, 2023

Summary

Small RFC in response to #14452. Keeps EnvVar as a direct subclass of str but implements a custom override of __str__ to fetch the value from the environment in the case that the user attempts to use the EnvVar anywhere.

In the case that it's passed into a resource or config, the resolution will still happen in a lazy manner.

A potentially compelling alternative could be to error on __str__ to explicitly prevent users from using EnvVar outside of resource/config contexts. Right now we're sort of in the worst of both worlds where a user can use an EnvVar in inapproporiate places and they get an odd result (see user comment in the above issue). (See #14490 for an example of this)

Test Plan

Small unit test, existing unit tests. Will expand suite if this is a direction we want to go.

@benpankow
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@schrockn
Copy link
Member

I think this is too magical and will end up confusing a different set of users for different reason.. I agree with having the conversion to the underlying environment name being an explicit method for our own internal purposes. I prefer #14490

Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

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

Definitely seems too magical. Seem comment in thread.

@benpankow benpankow closed this May 26, 2023
benpankow added a commit that referenced this pull request Sep 30, 2023
…ow direct usage (#14490)

## Summary

Alternative RFC to #14488. Keeps `EnvVar` as a direct subclass of `str`
but errors on resolving the value via `__str__` to explicitly prevent
users from using `EnvVar` outside of resource/config contexts. Right now
we're sort of in the worst of both worlds where a user can use an
`EnvVar` in inapproporiate places and they get an odd result.

1. Users who try to use an `EnvVar` value as a string will hit an error:

```python
my_env_var = EnvVar("MY_ENV_VAR")

# errors!
print(f"Hello, {my_env_var}!")
```

2. Users can directly access the `EnvVar` name or value:

```python
my_env_var = EnvVar("MY_ENV_VAR")

print(f"Env var {my_env_var.env_var_name} has value {my_env_var.get_value()}")
```

## Test Plan

Set of unit tests, existing unit tests.
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.

2 participants