Commit Graph

6 Commits

Author SHA1 Message Date
Dean Moldovan 5637af7b67 Add lightweight iterators for tuple, list and sequence
Slightly reduces binary size (range for loops over tuple/list benefit
a lot). The iterators are compatible with std algorithms.
2017-02-26 23:57:03 +01:00
Dean Moldovan 1fac1b9f5f Make py::iterator compatible with std algorithms
The added type aliases are required by `std::iterator_traits`.
Python iterators satisfy the `InputIterator` concept in C++.
2017-02-26 23:57:03 +01:00
Dean Moldovan f7685826e2 Handle all py::iterator errors
Before this, `py::iterator` didn't do any error handling, so code like:
```c++
for (auto item : py::int_(1)) {
    // ...
}
```
would just silently skip the loop. The above now throws `TypeError` as
expected. This is a breaking behavior change, but any code which relied
on the silent skip was probably broken anyway.

Also, errors returned by `PyIter_Next()` are now properly handled.
2017-02-26 23:57:03 +01:00
Dean Moldovan bad1740213 Add checks to maintain a consistent Python code style and prevent bugs (#515)
A flake8 configuration is included in setup.cfg and the checks are
executed automatically on Travis:

* Ensures a consistent PEP8 code style
* Does basic linting to prevent possible bugs
2016-11-20 21:21:54 +01:00
Ivan Smirnov 4c5e21b0cb Add tests for generalized iterators 2016-08-24 23:30:00 +01:00
Dean Moldovan a0c1ccf0a9 Port tests to pytest
Use simple asserts and pytest's powerful introspection to make testing
simpler. This merges the old .py/.ref file pairs into simple .py files
where the expected values are right next to the code being tested.

This commit does not touch the C++ part of the code and replicates the
Python tests exactly like the old .ref-file-based approach.
2016-08-19 13:19:38 +02:00