Commit Graph

11 Commits

Author SHA1 Message Date
konstin 6cd07c369c Simpler new and clippy fixes 2019-02-23 18:38:00 +01:00
konstin 936f0153e8 Migrate to rust 2018 2019-02-01 14:23:29 +01:00
konstin 302c099a76 Big refactoring to shrink the prelude 2018-09-21 23:34:28 +02:00
Paul Ganssle a05a78f7e0
Use smallest types for Py{Date}{Time} constructors
Because it's unlikely that anything other than the `year` parameter will
change in the C Python API, the rest can be restricted to their logical
ranges, which improves the compile-time error checking.
2018-08-21 18:33:33 -04:00
Paul Ganssle 5d5689f95b
Switch Py{Date}{Time} constructor parameters to i32
While the valid ranges for the constructor parameters is the same when
expressed as either u32 or i32, since the Python API uses i32 in their
public interface, we won't have to make any changes to the signatures if
the Python behavior changes (e.g. supporting negative years) without
their API changing.
2018-08-21 18:33:33 -04:00
Paul Ganssle 003351ba61
Get rid of unwrap_py! macro 2018-08-21 18:33:32 -04:00
Paul Ganssle bcc27bd522
Change datetime constructors to use Rust Option
This makes it cleaner to call PyTime::new and PyDateTime::new from Rust
without needing to retrieve a Python None.
2018-08-21 18:33:32 -04:00
Paul Ganssle 09ee50d4ca
Add tests for datetime overflow behavior
It *should* be safe to cast u32 to i32 in the case of the Py{Date}{Time}
constructors, because any unsigned values that would overflow would
raise an error anyway.

This adds tests to ensure that this is the case - they currently fail on
Python <3.6 because of a known issue with the Python C API.
2018-08-21 18:33:31 -04:00
Paul Ganssle ee658de1fb
Run rustfmt after datetime changes
Most of the datetime related changes were made before pyo3 switched to
using rustfmt, so I ran rustfmt only on the final commit to make it
easier to rewrite history as necessary (for fixups and whatnot).
2018-08-21 14:29:36 -04:00
Paul Ganssle 996c2baec8
Add preliminary Python 2 support to datetime bindings
The bounds checking tests are xfail because the datetime "fast path"
constructor didn't do bounds checking until bpo-29100 was resolved in
CPython commit b67f0967386a9c90411, which was merged for Python 3.6.

This functionality should be simple to backport to earlier versions in a
future commit.

BPO issue:
https://bugs.python.org/issue29100

CPython commit:
b67f096738
2018-08-21 14:29:36 -04:00
Paul Ganssle cd6f7295a1
Add type checking FFI bindings 2018-08-21 14:29:36 -04:00