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

Make Jinja2Templates.get_env private & rename #1218

Merged
merged 2 commits into from
Jun 27, 2021
Merged

Make Jinja2Templates.get_env private & rename #1218

merged 2 commits into from
Jun 27, 2021

Conversation

aminalaee
Copy link
Member

@aminalaee aminalaee commented Jun 26, 2021

Closes #1194.


def get_env(self, directory: str) -> "jinja2.Environment":
def _get_env(self, directory: str) -> "jinja2.Environment":
Copy link
Member

@Kludex Kludex Jun 26, 2021

Choose a reason for hiding this comment

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

@JayH5 I've been thinking about this kind of things:

Suggested change
def _get_env(self, directory: str) -> "jinja2.Environment":
def get_env(self, directory: str) -> "jinja2.Environment":
warnings.warn(
"'get_env' is deprecated. Use '_get_env' instead.",
DeprecationWarning,
)
return self._get_env(directory)
def _get_env(self, directory: str) -> "jinja2.Environment":

We did it for GraphQL, but we are in a pre-stable version, so in theory we can be aggressive and remove without adding warnings 🤔

Otherwise, we should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the whole idea is to shy away from using get_env direcrly. We can change the warning to encourage using templates.env instead of templates.get_env()

Copy link
Member

Choose a reason for hiding this comment

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

We definitely wouldn't want to suggest using a private method. We could say [...] Use the env attribute instead but even that is not equivalent to get_env.

If we wanted to be really careful we could rename this method to create_env and then call it from get_env with a warning like "this is deprecated, you probably want the env attribute, but if not use create_env". But, IMO, people should basically never want what get_env currently does and it's only confusing. I agree it should be removed.

Copy link
Member

Choose a reason for hiding this comment

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

We definitely wouldn't want to suggest using a private method.

Yeah, I agree! I've copied the warning from another snippet. 😛

But my intention here was to bring the discussion if we should keep adding warnings in pre-1.0.

@JayH5
Copy link
Member

JayH5 commented Jun 26, 2021

Thanks for the PR. I think it might make sense to rename this method _create_env to better reflect what it's actually doing.

@aminalaee aminalaee changed the title make-jinja2-get-env-internal rename-jinja2-get-env-and-make-internal Jun 26, 2021
@aminalaee aminalaee requested a review from JayH5 June 26, 2021 14:51
@aminalaee
Copy link
Member Author

Renamed to _create_env

@JayH5 JayH5 changed the title rename-jinja2-get-env-and-make-internal Make Jinja2Templates.get_env private & rename Jun 27, 2021
Copy link
Member

@JayH5 JayH5 left a comment

Choose a reason for hiding this comment

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

Thanks!

@JayH5 JayH5 merged commit 070d749 into encode:master Jun 27, 2021
@graingert graingert mentioned this pull request Jul 4, 2021
11 tasks
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.

Consider making starlette.templating.Jinja2Templates.get_env "protected"
3 participants