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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dependency on pytz #8984

Merged
merged 3 commits into from Jun 4, 2023
Merged

remove dependency on pytz #8984

merged 3 commits into from Jun 4, 2023

Conversation

deronnax
Copy link
Contributor

@deronnax deronnax commented May 15, 2023

No description provided.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

I think we should hold merging this, as older versions of django still support pytz and we also support them. so let's wait for future versions?

@deronnax
Copy link
Contributor Author

deronnax commented May 15, 2023

OK. Maybe we could remove pytz dependencies but keep the error handling code without having pytz imports , by catching the upper-level exception Exception, from which InvalidTimeError inherits?

@auvipy
Copy link
Member

auvipy commented May 16, 2023

@max-muoto what do you think

@max-muoto
Copy link
Contributor

@max-muoto what do you think

I'll take a look at this PR. Seems probable to me that it should work.

self.fail('make_aware', timezone=field_timezone)
return dt
except InvalidTimeError:
dt = timezone.make_aware(value, field_timezone)
Copy link
Contributor

@max-muoto max-muoto May 21, 2023

Choose a reason for hiding this comment

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

I think we should move this back to a try catch, and check that the exception's name using type(e).__name__, confirming it's equal to "InvalidTimeError". This way, we can still be specific, while removing the pytz dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

excellent idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hum, actually it only uses derived classes of InvalidTimeError. Should we iterate over the inheritance chain (__mro__) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I came out with something I find pretty good. The things I am annoyed with is: since we support both presence and absence of pytz in tests, the CI should test both and I doubt it does (and I yet don't see how without rerunning the test suite in a virtualenv with a different install)

@deronnax deronnax changed the title remove pytz remove dependency on pytz May 22, 2023
Comment on lines +13 to +16
try:
import pytz
except ImportError:
pytz = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this, so it's possible the @pytest.mark.skipif(pytz is None) on line 1598 never worked

@deronnax deronnax requested review from auvipy and max-muoto May 23, 2023 13:43
Copy link
Contributor

@max-muoto max-muoto left a comment

Choose a reason for hiding this comment

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

LGTM! @auvipy This looks like a perfect way of removing the dependency on pytz.

@auvipy auvipy added this to the 3.15 milestone Jun 4, 2023
@auvipy auvipy merged commit 376a5cb into encode:master Jun 4, 2023
7 checks passed
@auvipy
Copy link
Member

auvipy commented Jun 4, 2023

thanks a lot for handling this!

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.

None yet

3 participants