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

Add a st.timezones() strategy using the stdlib zoneinfo module #2630

Closed
Zac-HD opened this issue Sep 27, 2020 · 2 comments · Fixed by #2682
Closed

Add a st.timezones() strategy using the stdlib zoneinfo module #2630

Zac-HD opened this issue Sep 27, 2020 · 2 comments · Fixed by #2682
Assignees
Labels
new-feature entirely novel capabilities or strategies

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Sep 27, 2020

Python 3.9 adds the PEP 615 zoneinfo module to the standard library, and IMO we should add a corresponding hypothesis.strategies.timezones() - with #2414 to skew the distribution and help it find bugs.

I'm open to either adding a dependency on the backport (zoneinfo ; python_version<"3.9"), or just raising a runtime error if you try to use the strategy when zoneinfo is not available; leaning towards no dependency to avoid imposing any cost on people who aren't using it.

@Zac-HD Zac-HD added the new-feature entirely novel capabilities or strategies label Sep 27, 2020
@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 28, 2020

Note that @pganssle wrote the tricky bit, a valid_keys() strategy for zoneinfo keys like UTC or Australia/Sydney, for python/cpython#22863. Ideally we merge our version before CPython merges that, so they can use the new strategy from the start. Paul: I assume you can offer that strategy under the MPL-2.0 for Hypothesis?

I'm therefore leaning towards adding two strategies: st.timezone_names() for the names, and a convenience st.timezones() strategy implemented as return timezone_keys().map(zoneinfo.ZoneInfo) (similarly, the dateutil extra will be refactored as .map(dateutil.tz.gettz) to share #2414 heuristics).

@Zac-HD
Copy link
Member Author

Zac-HD commented Nov 26, 2020

Prototype: master...Zac-HD:zoneinfo

(needs tests and review by @pganssle, but I think it should mostly work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature entirely novel capabilities or strategies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant