Fix compatibility with non-pytz tzinfo objects#58
Fix compatibility with non-pytz tzinfo objects#58simon-weber merged 1 commit intosimon-weber:masterfrom
Conversation
The `.zone` attribute is a pytz specific extension.
|
Seems like pytz's |
|
Ah good spot @adamchainz. Looks like this should be strictly more compatible, and should allow for more edge cases in that case. |
|
After further testing there's another edge case that this doesn't account for. It's possible to have an un-named timezone, i.e. just an offset. These return I believe this would have been the case before this PR anyway, so I don't believe this is a regression and this PR could still be merged. I'll raise an issue for this behaviour. We aren't blocked on it so I probably won't get to fixing it myself for now I'm afraid. |
|
looks reasonable to me. thanks! |
|
@simon-weber thanks for this! Is it possible to get this shipped as a release? |
|
yup, I should be able to get to it within a day or two. |
|
released in 2.0.0: https://pypi.org/project/libfaketime/2.0.0/ |
My understanding of timezone code in Python is fairly limited, so please treat this as a proposal or a discussion point – it certainly needs review from someone with more understanding of the timezone ecosystem than myself.
That said, I believe what has happened here is that
python-libfaketimeis depending onpytzspecific functionality – thezoneattribute. From my exploration of thepytzanddateutilcodebases, it looks like thetznamemethod returns the same data. My understanding of the difference betweenpytzanddateutilis that with the former,tzinfoobjects know about their owningdatetime, whereas in the latter they don't (I could be wrong on this!).This PR uses these assumptions to change
fake_timeto calltzname(datetime_spec)instead of using.zonein the case that thedatetime_specis adatetime. A test is included to prevent regressions, although a review on whether this is the best wording of this test would be appreciated.This change fixes behaviour of
python-libfaketimein a codebase that makes extensive use ofdateutiland does not usepytz, where previously we had many test failures.