konstin
57afb51604
Remove PyToken completely; Fixes #94
2018-11-12 14:42:21 +01:00
konstin
fb2349b6ec
Remove PyToken usages from tests
2018-11-12 14:41:29 +01:00
konstin
d2ba436d6d
Remove the unnecessary type parameter PyObjectAlloc
2018-11-12 14:37:06 +01:00
konstin
9f45efebaf
Format
2018-11-11 12:25:53 +01:00
konstin
4c0ddbe61e
Merge pull request #263 from kngwyu/fix-240
...
Fix #240
2018-11-11 11:49:31 +01:00
kngwyu
bd6f923f43
Fix #240
2018-11-09 13:11:47 +09:00
ijl
50c6129607
NonNull pointer for Py, PyObject
2018-11-08 15:09:52 +00:00
konstin
52dfc0013c
Add doc example to PyIterator
2018-11-02 22:59:30 +01:00
konstin
9ffb2c617d
Run rustfmt
2018-11-02 22:59:30 +01:00
konstin
569db5fb02
Add test with generator to PyIterator
2018-11-02 22:59:30 +01:00
konstin
264f642f19
Better doc comment for PyObject
2018-10-31 11:58:19 +01:00
konstin
8b27f1e412
Get ready for rust 2018
2018-10-31 11:43:21 +01:00
konstin
dbaa2de061
Small improvements around function calling
2018-10-31 11:38:45 +01:00
kngwyu
625a3f6738
Added a test that call call_method with kwargs
2018-10-31 15:23:18 +09:00
kngwyu
607c23d287
kwargs: Option<PyDict> -> Option<&PyDict>
2018-10-31 15:07:28 +09:00
kngwyu
56b82c2f7d
Temporary hack to compile with latest nightly
2018-10-28 18:16:44 +09:00
konstin
38651a1827
Add tox config for pyo3 itself
2018-10-09 18:49:54 +02:00
konstin
4da9110489
Add tox config for word-count
2018-10-09 18:21:52 +02:00
kngwyu
9ab63f2289
Fix build with --features="num-complex"
2018-10-04 15:47:28 +09:00
konstin
5100676497
Splitted PyTypeCreate of PyTypeObject to remove specialization
2018-10-03 22:12:22 +02:00
konstin
71c584a110
De-specialize ToBorrowedObject
2018-10-03 21:04:49 +02:00
ijl
d0f79fb9fd
PyObjectProtocol::get_type_ptr()
2018-10-03 13:10:41 +00:00
ijl
38c6d942b7
Document UTF-8 FFI assumptions
2018-09-28 22:01:04 +00:00
ijl
851d2207c0
Simplify PyString, PyBytes, PyUnicode
...
PyStringData comments mention wanting to receive interpreter-
specific unicode types. I tried implementing this, but it's
more complex and slower to call libpython to fill a buffer
of u32 or such and convert that in Rust using widestring.
This implementation receives UTF-8 from PyUnicode_AsUTF8AndSize()
in python3 and PyUnicode_AsUTF8String() in python2. PyStringData
is removed as unnecessary.
The data() method on PyString, PyBytes, and PyUnicode is
replaced with as_bytes().
The python2 API changes improve the performance of
extracting unicode strings.
2018-09-28 21:47:44 +00:00
konstin
3a95d163ca
New rustfmt version
...
You might need to upgrade to the latest nightly to get the same results
2018-09-28 23:34:57 +02:00
konstin
8930bd00e0
Fix PyUnicode alias
2018-09-28 23:03:24 +02:00
konstin
0b1906b626
Merge branch 'master' into datetime-fix
2018-09-28 22:47:04 +02:00
kngwyu
f12e299f1c
Remove PyDateTime_*Types
2018-09-28 23:56:57 +09:00
Paul Ganssle
b869f09808
Add documentation to types/datetime.rs
...
This adds some light doc comments to the safe rust bindings.
2018-09-27 09:22:31 -04:00
Paul Ganssle
a528c1e877
Add documentation to the datetime ffi bindings
2018-09-27 09:20:11 -04:00
konstin
ed2739829f
Fix the other part from #231
2018-09-27 01:44:17 +02:00
konstin
78a5053b22
Fix #231
2018-09-27 01:11:31 +02:00
konstin
05874d3f1a
Fix tests
2018-09-27 01:11:31 +02:00
ijl
28bc3cf1e6
PyDict::from_sequence()
2018-09-25 14:19:23 +00:00
ijl
868e28d5ad
Fix segfault on calling unknown method
2018-09-24 02:49:52 +00:00
ijl
6a961298af
PyUnicode_AsUTF8AndSize, PyUnicode_AsUTF8 *const c_char API change
...
Noted in https://docs.python.org/3/c-api/unicode.html
2018-09-21 21:54:51 +00:00
konstin
302c099a76
Big refactoring to shrink the prelude
2018-09-21 23:34:28 +02:00
kngwyu
247da8d341
Implement pow, abs, neg for PyComplex
2018-09-21 14:48:43 +09:00
kngwyu
6b362a4654
Implement convsersion between num_complex::Complex and PyComplex
2018-09-21 14:23:01 +09:00
kngwyu
7ea875fc49
Implement Add/Sub/Mul/Div for &PyComplex
2018-09-21 12:48:42 +09:00
kngwyu
c6d588877b
Intoroduce PyComplex with minimum APIs
2018-09-20 11:52:57 +09:00
konstin
2904291b9e
Better code generation
2018-09-17 19:48:22 +02:00
konstin
10ef6cd111
Fix cfg on PyEval_InitThread to fix #219
2018-09-11 22:38:31 +02:00
konstin
d92e522243
Syn 0.15
2018-09-09 00:20:04 +02:00
konstin
ddc6313e74
#[pyclass]
objects can now be returned from rust functions
2018-09-06 18:04:13 +02:00
konstin
e6569ae61e
Remove ::pyo3::argparse::get_kwargs for from_borrowed_ptr_or_opt
2018-09-03 20:50:02 +02:00
konstin
29c882577c
Get rid of another default fn
2018-09-03 01:02:39 +02:00
konstin
f58549f1d8
Get rid of a bunch of PyTokens
2018-09-02 23:33:45 +02:00
konstin
0101dc8136
Two default fn less
2018-08-31 21:11:08 +02:00
konstin
aa8be251d3
Fix python 2
2018-08-29 22:47:02 +02:00
konstin
8de0574aad
Clippy stuff
2018-08-26 21:35:53 +02:00
konstin
7293cdbc6f
Remove dead impl
2018-08-26 19:14:55 +02:00
konstin
3b8adeb484
Rewrite sq_ass_item generation to avoid specialization
2018-08-26 19:09:34 +02:00
konstin
4847d56325
Less java-esque naming
2018-08-26 18:48:57 +02:00
konstin
6d9ee7fc38
Rewrite the set attr / del attr function to avoid specialization
2018-08-26 18:40:50 +02:00
konstin
7c0379b13a
Remove many specialization uses
...
From over a hundret "default fn" uses down to 17
2018-08-25 20:48:17 +02:00
konstin
33e72a2b03
Merge pull request #209 from joar/fix/escape-square-brackets
...
Escape square brackets when they're not references
2018-08-24 19:55:11 +02:00
Joar Wandborg
47bbe8cc1e
Use backticks instead of single quotes
...
The backticks properly monospace the Python expressions in the rendered
docs, and also escape square brackets inside so that rustdoc isn't
trying to parse them as references.
2018-08-24 19:15:48 +02:00
Joar Wandborg
b5e5bcf223
Escape square brackets in references.
2018-08-24 19:01:14 +02:00
konstin
3e7d5280ca
Merge pull request #200 from pganssle/datetime
...
Initial datetime bindings
2018-08-22 18:00:05 +02:00
Paul Ganssle
6202e2641b
Fix race condition in test_seq_set_item_refcnt
...
This test previously relied on a stable reference count for None, which
is not likely to be true in multi-threaded code. This creates an object
specifically for the test to avoid race conditions.
2018-08-21 20:32:12 -04:00
Paul Ganssle
c3986a7244
Fix race condition in test_borrowed*
...
This fixes a race condition in test_borrowed and test_borrowed_nested
by making the object under test different in each thread.
2018-08-21 20:20:24 -04:00
Paul Ganssle
c7a967c340
Silence type complexity warnings in ffi
2018-08-21 18:33:33 -04:00
Paul Ganssle
a09ffad32a
Add convnience function to unwrap Option<&PyObject>
2018-08-21 18:33:33 -04:00
konstin
7053c897aa
Get rid of #[inline(always)] and replace it with #[inline]
...
I've just seen that this had been hidden from clippy through the ffi module reordering, but fixing this on master would cause merge conflicts, so I'm fixing this here directly
2018-08-21 18:33:33 -04: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
b66ab7fabc
Move cache population logic into PyDateTime_IMPORT
...
This more closely mimics the CPython API, since the import logic
populates the global, it should also populate the cache.
This also allows users to eagerly initialize the Python C API if
preferred (for example, doing so before populating a bunch of threads,
or before making performance measurements that will be thrown off by a
lazy import).
2018-08-21 18:33:32 -04:00
Paul Ganssle
26c5397618
Implement Debug for PyObject in Python 2
...
For whatever reason I cannot build rustapi_module without this, and
rather than figure out the core problem, I figured that, for symmetry,
it makes sense to just implement Debug for PyObject.
2018-08-21 18:33:32 -04:00
Paul Ganssle
cf3b1d2cc3
Remove leading __ from private cache objects
...
These were basically cargo culted from lazy_static's implementation, but
they are not idiomatic or necessary to indicate that these are private
variables.
2018-08-21 18:33:32 -04:00
Paul Ganssle
a271ba9ed9
Use unified implementation for ffi::datetime
...
In the future we can make ffi::object, ffi::pycapsule, etc as
crate-public, but importing the specific symbols is a light touch way to
do this.
2018-08-21 18:33:32 -04:00
Paul Ganssle
3357fabb35
Remove 'Component' from ComponentAccess Traits
2018-08-21 18:33:32 -04:00
Paul Ganssle
f68d0932f4
Unwrap PyDateTime_CAPI function fields
...
Because the PyDateTime_CAPI is always accessed via a lazy-initialized
static reference, it is not necessary to handle the case where the
functions on the C struct have not been initialized.
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
bcc42315ff
Inline parameter typecasts
...
Clippy complains about the one-letter variables, but it's preferable to
do the typecasts in-line anyway.
2018-08-21 18:33:31 -04:00
Paul Ganssle
94bd0d7b6d
Relax constraints on PyDateTimeAPI initialization
...
As noted in the comments, using call_once to initialize the
PyDateTimeAPI singleton is causing deadlocks with the GIL; these
deadlocks can be avoided by falling back on CPython's own locking
behavior.
2018-08-21 18:33:28 -04:00
konstin
771d59b913
Fix another bunch of clippy lints
2018-08-21 23:51:13 +02:00
Paul Ganssle
12c20a75d9
Move datetime interface to exclusively use functions
2018-08-21 14:29:36 -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
Paul Ganssle
f701bccbdf
Add PyTime component accessors
2018-08-21 14:29:36 -04:00
Paul Ganssle
ecf3aaafb2
Add PyDateTime component accessors
2018-08-21 14:29:35 -04:00
Paul Ganssle
0b39452276
Add accessors to PyDateTime_Date
2018-08-21 14:29:35 -04:00
Paul Ganssle
08e7e0f55a
Add PyDelta component accessors
...
Adds the PyDateTime_DELTA_GET_{comp} accessors and bindings to them in
the PyDelta object.
2018-08-21 14:29:35 -04:00
Paul Ganssle
f47697e2b5
Refactor pyobject_* macros
...
See 8c26020015
for general change.
2018-08-21 14:29:35 -04:00
Paul Ganssle
f5e0785654
Add time_with_fold
2018-08-21 14:29:35 -04:00
Paul Ganssle
c49bbe4549
Add PyDateTime::from_timestamp
2018-08-21 14:29:34 -04:00
Paul Ganssle
7256bc85b7
Add PyDate::from_timestamp
2018-08-21 14:29:34 -04:00
Paul Ganssle
e8d6a4bcc0
Version qualify PyDateTimeAPI
2018-08-21 14:29:34 -04:00
Paul Ganssle
8d781cb03f
Add datetime.timedelta
2018-08-21 14:29:34 -04:00
Paul Ganssle
f45362943d
Add datetime.time
2018-08-21 14:29:34 -04:00
Paul Ganssle
d7b90c1b3a
Add datetime.datetime and switch to PyResult<Py<T>>
2018-08-21 14:29:34 -04:00
Paul Ganssle
496b879525
Add objects/datetime.rs
2018-08-21 14:29:33 -04:00
Paul Ganssle
2b74cdbd57
Add initial bindings for datetime.h
2018-08-21 14:29:31 -04:00
konstin
82129c70b4
Added an explenation that the GIL can temporarily be released even while holding a GILGuard
2018-08-20 22:56:24 +02:00
konstin
db4a2d9017
Get rid of the pyobject_extract macro
2018-08-20 22:53:43 +02:00
konstin
991a8b94d2
More nightly fixes
2018-08-19 20:42:17 +02:00
konstin
b12b65cfae
Cleanup
2018-08-19 20:06:47 +02:00
kngwyu
ff2871f325
Remove unnecessary feature gates from doc tests
2018-08-14 18:29:15 +09:00
konstin
d0ed68414a
Many small improvements
2018-08-04 19:56:59 +02:00
konstin
fe8a719ee1
Rustfmt all the things ✔️
2018-07-30 23:05:10 +02:00
konstin
83db765889
Refactoring
2018-07-30 22:56:25 +02:00
konstin
d9d1650fc4
Fix #197 - Remove tuple to dict conversions
2018-07-30 22:52:36 +02:00
konstin
27633da3b1
Merge pull request #191 from milesgranger/master
...
Python::run should return PyObjectRef result
2018-07-30 17:49:57 +02:00
Miles Granger
a13b79459f
Return PyObjectRef result from Python::run
2018-07-29 22:00:36 +02:00
kngwyu
5e1ce01251
Enable generics parameter in pyobject_native_type!
2018-07-28 14:46:00 +09:00
konstin
2627fa8a08
0.3.2
2018-07-22 21:36:18 +02:00
konstin
ff70f45071
(Hopefully) get travis to build the guide for tags
2018-07-18 23:28:14 +02:00
konstin
3adcac6e61
Replace concat_idents with mashup
2018-07-18 23:17:05 +02:00
konstin
7d4381fc5d
Fixed scoping bug in pyobject_native_type that would break rust-numpy
2018-07-18 14:06:17 +02:00
konstin
d59bebcc38
Upgrade from proc_macro to use_extern_macros
2018-07-18 13:08:05 +02:00
konstin
eb613c64d9
Add repr(transparent) where applicable
2018-07-13 18:10:09 +02:00
konstin
fe931a594f
#[pymodinit] now uses the function name as default module name
2018-07-10 00:13:02 +02:00
konstin
4013d40897
Add py
prefix to the proc macros and move them into the root module
...
This is important because `proc_macro_path_invoc` isn't going to be stabilized soon.
2018-07-08 23:33:48 +02:00
konstin
68c14a5707
Merge branch 'master' of https://github.com/PyO3/pyo3
2018-07-03 21:55:43 +02:00
konstin
28d6c9986c
Fix clippy errors
2018-07-03 21:32:16 +02:00
konstin
43eb5fa490
Rename prepare_pyo3_library to init_once
2018-07-03 21:12:57 +02:00
konstin
6645708e4f
Get rid of #[py*] methods
2018-07-03 20:42:02 +02:00
kngwyu
7d7c1ede49
Modify pyobject_native_type to take expr
...
To use deref(*) expression
2018-07-02 16:31:36 +09:00
kngwyu
41f4d1d673
$crate::std to ::std
...
So that we can use these macros in outer crates
2018-07-02 00:06:08 +09:00
kngwyu
70e1879d59
Make python pub
2018-07-02 00:06:01 +09:00
kngwyu
3ec49b586f
Modify pyobject_native_type to take path instead of ident
...
So that we can use this macro outside this crate.
2018-07-01 23:51:56 +09:00
konstin
f9ff7cd465
Ignore test because of a docmatic bug
...
See https://github.com/assert-rs/docmatic/issues/4
2018-06-15 15:59:22 +02:00
konstin
1301394264
Fix c string conversion in python 2
2018-06-15 15:57:59 +02:00
konstin
7a52bf647c
Apply fixes by Philip Molloy
2018-06-14 16:03:05 +02:00
konstin
54b09c704b
Fix -Z minimal-versions
2018-06-06 21:18:42 +02:00
kngwyu
66183d4683
Move common functions and macros from num2&num3 to num_common
2018-06-06 01:31:40 +09:00
kngwyu
0b964b503f
Rename args of _PyLong_FromByteArray/_PyLong_AsByteArray
2018-06-05 23:03:53 +09:00
kngwyu
9ffbae30ab
Add 128bit integer support for python2
2018-06-02 22:10:13 +09:00
kngwyu
a87ddeab21
Add 128bit integer support for python3
2018-06-02 22:08:29 +09:00
kngwyu
4795a35143
impl IntoPyDictPointer for IntoIterator<Item=(K, V)>
...
this commit has 2 purposes:
1. Avoid duplication of implementation(for BTreeMap & HashMap)
2. Enable conversion from Vec<(K, V)> to PyDict
2018-05-30 16:26:23 +09:00
Kevin Phillips
9544adaf1d
Marked from_code on PyModule to only work with Python 3. It could work with Python 2 if you call, for example, Py_CompileStringFlags and pass std::prt::null_mut() as the last argument and when calling PyImport_ExecCodeModuleEx passing mutable pointers for the first and last arguments. I also added a test for this to test_module.rs
2018-05-21 16:03:21 +02:00
Kevin Phillips
1b1121e558
Added a function to PyModule to load a module from a string of Python
2018-05-21 16:03:20 +02:00
konstin
c42b71bc55
Fix python2
2018-05-19 17:42:40 +02:00
konstin
314a4a2b3e
Some more documentation work
2018-05-19 17:27:26 +02:00
konstin
46b9bd6a9f
Merge pull request #155 from PyO3/pyobject_macros
...
Refactor and Export Pyobject_* macros
2018-05-13 14:54:57 +02:00
konstin
5717463daf
Merge pull request #154 from konstin/capybara
...
Relax return types and add functions
2018-05-12 20:43:40 +02:00
Martin Larralde
416a7fd8d3
Export PyUnicode in Python3 as well
2018-05-08 12:54:21 +02:00
konstin
d445d60e0a
Export PyUnicode to fix #141
2018-05-08 10:42:17 +02:00
konstin
cb5bae2c90
Export pyobejct_* macros
...
This is required for interaction with other native python extensions, e.g. numpy
Fixes #153
2018-05-07 23:47:23 +02:00
konstin
8c26020015
Refactor pyobject_* macros
2018-05-07 23:45:24 +02:00
konstin
858a124374
Merge master
2018-05-05 15:50:04 +02:00
konstin
afcc87e82c
Feature gate try_from
...
This was discovered https://github.com/PyO3/pyo3/issues/5#issuecomment-386579894
2018-05-05 14:43:37 +02:00
konstin
57048bc5fc
Merge branch 'master' into capybara
2018-05-02 19:32:56 +02:00
konstin
15204bab56
Better way to add functions to modules
2018-05-02 19:26:54 +02:00
Martin Larralde
cc352dade3
Fix exception
tests failing with Python 2
2018-05-02 13:54:59 +02:00
Martin Larralde
b80b85539b
Remove occurrences of py::methods
and py::class
2018-05-01 23:17:42 +02:00
konstin
0880ac166c
Merge master
2018-05-01 20:41:35 +02:00
konstin
d0c42dfcc1
Fix compilation on nightly
2018-05-01 15:44:38 +02:00
konstin
6113428746
Allow defining functions outside of the module declarations
...
This commit consists of
* a proc macro to convert rust functions into python functions (`#[function]`),
* a macro to register a function in a module (`add_function_to_module!`)
* Documenting both the old and the new way in the book
2018-04-30 23:17:09 +02:00
konstin
1c0eac2690
Minor changes
2018-04-09 00:00:20 +02:00
konstin
45bb09b3e8
Relax return type requirements
...
Allows returning essentially arbitrary types by wrapping them into a PyResult. This is done with a conversion trait that specializes for PyResult.
2018-04-06 17:22:09 +02:00
Alexey Popravka
e66c5ebb83
use PyTryFrom explicitly
2018-03-29 17:36:05 +03:00
Vlad Shcherbina
2aedbffcd0
Fix typos
2018-03-15 14:41:16 +03:00
Ethan Smith
5cc6dc74d4
conditionally include Python3.6 items
2018-03-01 14:46:27 -08:00
Ethan Smith
6c25a753b8
Add PEP 523 frame eval API things
2018-03-01 13:36:16 -08:00
Roy Wellington Ⅳ
11e2163bb4
Fix minor typos in example code
2018-02-22 22:22:37 -08:00
Martin Larralde
e58cd1c585
Fix wrong macro being tagged with macro_export
2018-02-21 22:44:56 +01:00
Nikolay Kim
995ec109c3
Merge pull request #116 from althonos/master
...
Allow importing exceptions from nested modules
2018-02-21 10:35:11 -08:00
Nikolay Kim
057660e546
fix python3.7 support
2018-02-21 10:29:14 -08:00
Martin Larralde
cce9d0de56
Allow importing exceptions from nested modules
2018-02-21 19:16:17 +01:00
Nikolay Kim
d50d1fb7ea
enable python3.7 builds
2018-02-21 10:06:48 -08:00
Nikolay Kim
0b9557a245
call_method*() crashes when the method does not exist #113
2018-02-21 09:39:06 -08:00
Nikolay Kim
b7a8d25338
const fns that we use are stable now
2018-02-21 09:23:58 -08:00
Nikolay Kim
438f4bf091
ignore some python code in doc strings
2018-02-21 09:23:52 -08:00
Vlad Shcherbina
a59e1dc8ad
Fix unused_parens warnings
...
I left the parentheses in place to keep the resemblance
to the original C macros.
2018-02-12 14:36:05 +03:00
Vlad Shcherbina
a5d3ed0939
Add tests that string/float to int conversions raise TypeError #108
2018-02-11 19:09:15 +03:00
Vlad Shcherbina
9fe78b5cb3
Disallow implicit weakly-typed conversions to integers #108
...
In `int_fits_c_long!`,
use `PyLong_AsLong(PyNumber_Index(x))`
instead of `PyNumber_Index(x)`.
In `int_convert_u64_or_i64!`,
use `PyLong_As*LongLong(PyNumber_Index(x))`
instead of `PyLong_As*LongLong(if PyLong_Check(x) {x} else {PyNumber_Long(x)})`.
Along the way, fix memory leak caused by missing `Py_DECREF(num)`.
`PyNumber_Index(x)` is the best way to get an integer losslessly:
https://docs.python.org/3/reference/datamodel.html#object.__index__
https://docs.python.org/3.5/c-api/number.html#c.PyNumber_Index
`PyLong_AsLong(x)` has the problem that it attempts to call `x.__int__()`.
Strings don't implement this method, but floats do, so it silently converts
floats to integers.
https://docs.python.org/3.5/c-api/long.html#c.PyLong_AsLong
`PyNumber_Long(x)` is equivalent to `int(x)` call,
so not only does it truncate floats, but also attempts to parse strings.
https://docs.python.org/3.5/c-api/number.html#c.PyNumber_Long
`PyLong_Check(x)` is redundant because it happens inside `PyNumber_Index(x)`
anyway:
988fb28431/Objects/abstract.c (L1259)
2018-02-11 19:04:12 +03:00
Vlad Shcherbina
f8e503f3b7
Drop tests for implicit float to int conversions #108
...
Neither Python nor Rust has implicit float to integer conversions
(they mask programming errors), so it would make sense for the
bindings library to disallow them as well.
Later there will be tests that such conversions result in TypeError.
2018-02-11 18:19:21 +03:00
Vlad Shcherbina
81fd4bd24e
Remove PyEval_ThreadsInitialized() assertion #110
...
First, this function should not be called before `Py_Initialize()`.
It accesses the field `_PyRuntime.ceval.gil.locked` of the global
variable, which is zero initially, but uses -1 to indicate that
the GIL is not created or destroyed.
(8ff5356473/Python/ceval_gil.h (L98)
)
Second, this assertion can't be moved after `Py_InitializeEx(0)` call,
because in Python 3.7 they started calling `PyEval_InitThreads()`
from `Py_Initialize()`.
(2914bb32e2 (diff-baf5eab51059d96fb8837152dab0d1a4R689)
)
2018-02-10 21:36:59 +03:00
Nikolay Kim
3681cf51e8
python2 compatibility
2018-01-19 10:08:13 -08:00
Nikolay Kim
b738c1a04b
clippy warnings
2018-01-19 10:02:36 -08:00
Nikolay Kim
324a6b2697
drop RefFromPyObject; allow mut refs #106
2018-01-19 09:04:42 -08:00
Nikolay Kim
35e91a5cd1
Merge branch 'master' of github.com:PyO3/pyo3
2018-01-17 08:10:01 -08:00
Nikolay Kim
d6035bce15
Fix impl FromPyObject for Py<T>
2018-01-17 08:09:44 -08:00
Guanqun Lu
4bc079f619
typo fix
2017-12-27 22:11:18 +08:00
Nikolay Kim
050397b723
mark method that work with raw pointer unsafe
2017-12-26 13:41:27 -08:00
Nikolay Kim
d3832359a2
proper c_char usage #93
2017-11-27 10:59:45 -08:00
messense
e7a7b3d5a0
Remove use of now unneeded 'AsciiExt' trait
2017-11-23 12:08:05 +08:00
dkao1978
eb9050ab90
Add documentation for compiling on MacOS ( #89 )
...
* Update README.md
* Update overview.md
* Update lib.rs
* Update README.md
* Add links
2017-10-22 11:17:35 +08:00
messense
95d94c19b3
Rustup to 1.22.0-nightly 2017-09-30
2017-10-01 20:32:35 +08:00
messense
e5780ed2b8
Add const_ptr_null_mut feature to a doctest
2017-09-19 20:09:46 +08:00
messense
703883687a
Add features to tests
2017-09-19 20:03:03 +08:00
messense
9da1247484
Fix build on rustc nightly-2017-09-16
...
Use forked version of spin-rs for now.
Closes #79
2017-09-19 19:51:25 +08:00
Nikolay Kim
25472e5428
cleanup warnings
2017-08-11 20:47:37 -07:00
Nikolay Kim
b92056b429
update doc string
2017-08-11 20:42:26 -07:00
Nikolay Kim
03b6e5c122
refactor object allocation system
2017-08-11 20:17:09 -07:00
Nikolay Kim
ed8599cfd3
refactor __new__ method implementation
2017-08-08 00:27:33 -07:00
Nikolay Kim
3b00145040
fix #[prop] impl
2017-08-07 23:52:24 -07:00
Nikolay Kim
11f244692e
add convenience call related methods to ObjectProtocol
2017-08-04 11:47:51 -07:00
Nikolay Kim
a61c5e56a0
add convenience method to PyErr and exception types
2017-08-04 11:47:35 -07:00
Nikolay Kim
21939c4d8b
drop PyNativeException
2017-08-03 17:07:13 -07:00
Nikolay Kim
16297a9917
restore release method
2017-08-03 16:57:59 -07:00
Nikolay Kim
19d20471c9
fix import_exception macro
2017-08-03 16:57:46 -07:00
Nikolay Kim
130c33ec09
export IntoPyDictPointer
2017-08-03 15:55:23 -07:00
Nikolay Kim
590edad93c
rename get_super()
2017-08-03 15:45:28 -07:00
Nikolay Kim
06a0b0514b
add IntoPyDictPointer impl for tuple
2017-08-03 15:42:32 -07:00
Nikolay Kim
cd6558a19b
Introduce IntoPyDictPointer similar to IntoPyTuple #69
2017-08-03 15:01:52 -07:00
Nikolay Kim
b3cc6f1e61
fix clippy warnings
2017-08-03 11:55:39 -07:00
Nikolay Kim
5537ece078
fix unstable tests
2017-08-03 11:37:24 -07:00
Nikolay Kim
85eced19dd
add IntoIterator for PyDict
2017-08-03 11:04:45 -07:00
Nikolay Kim
e652383004
added IntoIterator for PyList
2017-08-03 10:47:26 -07:00
Nikolay Kim
b7f3231ecd
improve iterator support for PyTuple
2017-08-03 10:39:01 -07:00
Nikolay Kim
44da09a0f4
add std TryFrom impl for type conversion #73
2017-08-02 14:47:54 -07:00
Nikolay Kim
e44365bec6
make cast_xxx api consistent with PyObject::from_xxx api
2017-08-01 14:29:25 -07:00
Nikolay Kim
5dad22e3db
temp fix for #71
2017-08-01 14:09:13 -07:00
Nikolay Kim
95915b55dd
Merge branch 'master' of github.com:PyO3/pyo3
2017-07-31 10:43:23 -07:00
Nikolay Kim
c44e23f4b9
add prelude mod
2017-07-31 10:42:55 -07:00
messense
6a545f4abb
Less allocation in extract_sequence
2017-07-31 22:33:28 +08:00
Nikolay Kim
325070f6c9
refactor downcast process
2017-07-28 23:19:00 -07:00
messense
0e2afb7b8b
Add __dict__ support ( #68 )
2017-07-28 22:21:59 +08:00
messense
60f6a73217
Impl IntoPyObject for HashMap and BTreeMap ( #67 )
2017-07-28 12:36:45 +08:00
Nikolay Kim
aa5b4af1d4
custom dealloc for py3
2017-07-27 20:08:09 -07:00
Nikolay Kim
afcfed492b
only c classes only as base class
2017-07-27 19:47:01 -07:00
Nikolay Kim
665a1da016
added PySuper and __init__ support
2017-07-27 16:20:21 -07:00
messense
ebcd4f5a33
subclass support ( #64 )
2017-07-27 23:05:15 +08:00
Nikolay Kim
d567817035
add base support for inheritance
2017-07-26 22:29:55 -07:00
Nikolay Kim
8227ce81e2
various cleanups
2017-07-26 20:29:07 -07:00
Nikolay Kim
67ce4e4516
fix long type
2017-07-26 18:46:22 -07:00
Nikolay Kim
139a31b1e4
implement ToPyObject and IntoPyObject for PyErr
2017-07-26 16:13:45 -07:00
Nikolay Kim
e5c1fcf11d
no need mut for PyErr::clone_ref; IntoPyTuple::to_tuple is not needed
2017-07-26 15:08:34 -07:00
Nikolay Kim
fc3ab84bfa
better constrain for PyNativeException::new
2017-07-26 14:56:08 -07:00
Nikolay Kim
a4fd878cb7
pyerr cleanups
2017-07-26 14:28:04 -07:00
Nikolay Kim
a20230e73f
Create rust type for exceptions defined in python #45
2017-07-26 12:56:07 -07:00
Nikolay Kim
e45eb6e878
rename ToPyErr to PyErrArguments
2017-07-26 10:47:17 -07:00
Nikolay Kim
b250ad22ca
update guide related to exception
2017-07-26 09:16:26 -07:00
Nikolay Kim
a120bbf15e
Refactor implementation. Drop parameter from constructor
2017-07-26 01:11:00 -07:00
Nikolay Kim
86252cda4c
simplify PyTypeInfo and PyTypeObject
2017-07-25 18:39:11 -07:00
Nikolay Kim
65a42a2b1a
remove py param
2017-07-25 18:11:45 -07:00
Nikolay Kim
3ab5e4526c
add weakref support #56
2017-07-24 13:03:18 -07:00
Nikolay Kim
ce15dda5b6
Allow to add gc support without implementing PyGCProtocol #57
2017-07-24 12:19:05 -07:00
messense
1834ec4a33
Add PyDict::iter
2017-07-23 22:46:04 +08:00
Nikolay Kim
98bdf63a4d
use const_fn for type size and offset calculation
2017-07-21 09:48:48 -07:00
Nikolay Kim
2ee6419464
do not catch rust panics
2017-07-20 14:21:57 -07:00
Nikolay Kim
5f1a410d6e
more cleanups
2017-07-20 09:11:28 -07:00
Nikolay Kim
0756e341a8
cleanup PyModule
2017-07-20 08:33:30 -07:00
Nikolay Kim
a00ae1757c
add PyDict keys,values,items methods
2017-07-20 08:23:43 -07:00
Nikolay Kim
97c6b7591a
added PyList::append method, added refcnt tests
2017-07-20 08:05:12 -07:00
Nikolay Kim
e23c7247e6
fix memory leak in PyList::set_item and insert_item
2017-07-19 22:22:19 -07:00
Nikolay Kim
1035aaae49
fix python2 related code
2017-07-19 13:22:26 -07:00
Nikolay Kim
13820f4ce3
added PyTuple::slice and PyTuple::split_from methods
2017-07-19 13:04:58 -07:00
Nikolay Kim
f344c4ce3d
added try downcast methods to PyDowncastFrom trait
2017-07-19 13:01:59 -07:00
Nikolay Kim
9cecfc0ec9
fix fn names
2017-07-19 09:27:19 -07:00
Nikolay Kim
63baa575a6
fix memory leak in call and call_method
2017-07-19 09:22:54 -07:00
Nikolay Kim
5559dbb9ed
fix memory leak
2017-07-19 06:35:59 -07:00
Nikolay Kim
c6067b90c1
more docs
2017-07-18 14:15:44 -07:00
Nikolay Kim
01d688fc98
use better name for Pointers
2017-07-18 11:12:35 -07:00
Nikolay Kim
fc1df289bd
drop PyClone trait; doc cleanups
2017-07-18 10:13:50 -07:00
messense
dd29dbce80
Use std::ptr::null() and std::ptr::null_mut() ( #51 )
2017-07-18 23:23:21 +08:00
messense
5a8fd2febc
Some more clippy warning fixes
...
[rustfix](https://github.com/killercup/rustfix ) makes it much easier.
2017-07-18 22:10:56 +08:00
messense
e69163344a
Fix some clippy warnings ( #49 )
2017-07-18 19:28:49 +08:00
Nikolay Kim
2d06b07717
fix PyNumberProtocol methods #48
2017-07-17 16:49:19 -07:00
Nikolay Kim
149aa3a0eb
always inline all py()
2017-07-14 16:21:18 -07:00
Nikolay Kim
292bd2c139
inline py() call
2017-07-14 14:21:07 -07:00
Nikolay Kim
4daac50781
remove associated_consts feature
2017-07-14 03:17:57 -07:00
Nikolay Kim
c5f5620f77
rename token() to py()
2017-07-13 19:04:00 -07:00
Nikolay Kim
fb8b32072f
add basic args test
2017-07-13 18:50:34 -07:00
Nikolay Kim
8eb5dc0667
use associated consts
2017-07-13 16:45:50 -07:00
Nikolay Kim
ed31492d36
rename pointer mod to object
2017-07-13 13:05:50 -07:00
Nikolay Kim
27f8747ba6
safe typeob dealloc and tests for release pools
2017-07-13 13:01:31 -07:00
Nikolay Kim
49de1f1d40
cleanup cb_unary and gc protcol
2017-07-10 00:40:30 +06:00
Nikolay Kim
ce05cb91c0
fix pointer release list
2017-07-10 00:37:20 +06:00
Nikolay Kim
c1c4648add
delay decref until gil available
2017-07-09 12:08:57 +06:00
Nikolay Kim
a90d8c241f
fix ref counter for get_kwargs
2017-07-04 10:24:04 +06:00
Nikolay Kim
3028dcf58f
fix error from instancel fixed bool
2017-06-30 08:51:45 +06:00
Nikolay Kim
afe2324ecc
fix api inconsystency
2017-06-29 11:23:55 +06:00
Nikolay Kim
8bc1195f12
Merge branch 'master' of github.com:PyO3/PyO3
2017-06-27 05:06:09 +06:00
Nikolay Kim
503e4221cc
support &str as fn param
2017-06-24 15:28:53 -07:00
Nikolay Kim
082db89aa6
do not modify ref counter for borrowed ptr
2017-06-24 12:57:18 -07:00
messense
2d217be349
Use isize for hash protocol
2017-06-24 23:43:01 +08:00
Nikolay Kim
3a2004eab2
rename PyInstance to PyObjectRef
2017-06-24 08:28:31 -07:00
messense
4e836cb229
Don't reexport Py_hash_t and Py_ssize_t
2017-06-24 22:36:45 +08:00
messense
378fae9659
Hide argparse module in API docs
2017-06-24 22:30:46 +08:00
messense
a5e3429d60
Remove unnecessary ObjectProtocol
import
2017-06-24 22:29:35 +08:00
messense
0ba541e762
Add missing module level docs
2017-06-24 16:47:36 +08:00
messense
84ebdbcfe9
Add copyright headers to some files
2017-06-24 16:36:51 +08:00
Nikolay Kim
d80eee6fba
move IterNextResultConverter to proper location
2017-06-23 16:37:31 -07:00
Nikolay Kim
352774744a
use StopAsyncIteration for __anext__ #35
2017-06-23 16:11:50 -07:00
Nikolay Kim
64f120a8f7
review system exceptions
2017-06-23 16:00:44 -07:00
Nikolay Kim
14c6aaad55
py.init returns ptr, init_ref and init_mut ref and mut ref
2017-06-23 15:15:07 -07:00
Nikolay Kim
8238a141ae
py.init(..) return reference
2017-06-23 15:03:52 -07:00
Nikolay Kim
f0ece6dfde
added doc strings
2017-06-23 13:50:27 -07:00
Nikolay Kim
3e3fed9c18
remove True and False python methods
2017-06-23 13:42:46 -07:00
Nikolay Kim
b1e6f07060
fix doc comments
2017-06-23 13:27:18 -07:00
Nikolay Kim
cc56ded6bf
fix python2 extension module initialization
2017-06-23 11:51:15 -07:00
Nikolay Kim
61f85c730e
fix doc tests; fix unsued import warning
2017-06-23 10:38:04 -07:00
Nikolay Kim
006e38cd6e
fix kwargs for py methods
2017-06-23 10:06:41 -07:00
Nikolay Kim
a58aa7b5e6
rename PyObject
2017-06-22 20:56:09 -07:00
Nikolay Kim
2faf18bb9e
rename token method
2017-06-22 13:35:21 -07:00
Nikolay Kim
00bd5615ed
drop py paramater for protcol definitions
2017-06-22 12:32:01 -07:00
Nikolay Kim
cb969161c6
fix unchecked downcast; added objects pool
2017-06-22 10:26:07 -07:00
Nikolay Kim
b9377849c8
rename modules
2017-06-22 01:16:22 -07:00
Nikolay Kim
c48386affa
stopping point
2017-06-22 01:04:37 -07:00
Nikolay Kim
397f50571b
do not derive Debug for GILGuard
2017-06-21 15:17:16 -07:00
Nikolay Kim
af663e0f80
update PyType
2017-06-21 15:11:32 -07:00
Nikolay Kim
7cf8e1ab80
modify PyDict
2017-06-21 14:08:16 -07:00
Nikolay Kim
96788bf192
more types
2017-06-21 13:10:40 -07:00
Nikolay Kim
e9341d6f05
add release pool
2017-06-21 12:33:27 -07:00
Nikolay Kim
08ddb3f14f
other types
2017-06-21 12:33:21 -07:00
Nikolay Kim
bc0f9b014f
convert PyString object
2017-06-20 23:27:30 -07:00
Nikolay Kim
ce53e8230b
add downcast traits to Py
2017-06-20 15:09:12 -07:00
Nikolay Kim
c4ba2b0f2e
rename InstancePtr to AsPyRef
2017-06-20 14:22:49 -07:00
Nikolay Kim
40efa5c955
rename Ptr to Py
2017-06-19 23:57:34 -07:00
Nikolay Kim
7b5521fdb3
simplify instance ptr, droped #[py::ptr] annotation attr
2017-06-19 20:55:07 -07:00
Nikolay Kim
b4deb673c7
refactor #[args()] attribute #40
2017-06-19 14:05:14 -07:00
Nikolay Kim
005c36548b
add specialization to docs
2017-06-18 09:28:21 -07:00
messense
75d6684d25
Clarify Python module doc string
2017-06-18 23:15:10 +08:00
messense
f681038133
Prefer expect()
and map_err()
to unwrap()
2017-06-17 17:40:11 +08:00
Nikolay Kim
60a965edc3
update link to example py extension
2017-06-15 14:30:11 -07:00
Nikolay Kim
e85db971f9
fix module export functions
2017-06-15 14:20:30 -07:00
Nikolay Kim
f4d0fe3950
docs cleanup
2017-06-15 13:13:52 -07:00
Nikolay Kim
edc9fc1b7f
hide some traits
2017-06-15 11:43:38 -07:00
Nikolay Kim
0679fec859
update docs
2017-06-15 11:13:58 -07:00
Nikolay Kim
ac0594a5b2
do not use pub pointers mod
2017-06-15 10:36:41 -07:00
Nikolay Kim
3bed79fe0b
add clippy and doc to travis
2017-06-15 09:11:19 -07:00
Nikolay Kim
5bf6ce3864
added __unicode__ method to PyObjectProtocol
2017-06-15 07:48:57 -07:00
Nikolay Kim
bd7a0feb8c
merge master
2017-06-15 07:16:40 -07:00
messense
b8b9daf67a
Enable doc test for src/lib.rs examples
2017-06-15 16:06:04 +08:00
Nikolay Kim
d9bd485072
macro_use is not requires
2017-06-14 14:42:05 -07:00
Nikolay Kim
293569b6af
remove import
2017-06-14 14:23:51 -07:00
Nikolay Kim
b67954fd19
remove GILProtected
2017-06-14 14:15:29 -07:00
Nikolay Kim
706477f139
replace py_fn! macro with pyfn attribute
2017-06-14 14:08:30 -07:00
Nikolay Kim
319ee30c79
new impl for #[args] attribute
2017-06-13 22:37:26 -07:00
Nikolay Kim
7379766ea8
added __doc__ to methods
2017-06-12 21:08:59 -07:00
Nikolay Kim
d7c3d34198
add class doc string
2017-06-12 17:15:26 -07:00
Nikolay Kim
6204a06cbc
update docstring
2017-06-11 23:54:24 -07:00
Nikolay Kim
52df3a4323
Merge branch 'master' of github.com:PyO3/PyO3
2017-06-11 22:24:05 -07:00
Nikolay Kim
26fccf6022
added proper PyString for py2 handling
2017-06-11 22:23:49 -07:00
messense
f07e562251
PyType.is_instance/is_subclass should not consume self
2017-06-12 11:56:19 +08:00
Nikolay Kim
b21ded3aaa
added PyInt for py2
2017-06-11 20:36:57 -07:00
Nikolay Kim
8d4e0204f1
move PyFloat to separate module
2017-06-11 20:04:34 -07:00
Nikolay Kim
d619ded980
use Py_TPFLAGS_CHECKTYPES for py2
2017-06-11 19:45:01 -07:00
Nikolay Kim
fdd9ac7ae9
various improvements
2017-06-11 18:30:56 -07:00
Nikolay Kim
03ced8917b
PyString for py2
2017-06-11 17:20:18 -07:00
Nikolay Kim
805429e0f4
remove unneeded macro
2017-06-11 16:49:25 -07:00
Nikolay Kim
05d4a0a9a4
rename ffi to ffi3
2017-06-11 16:47:27 -07:00
Nikolay Kim
3b4d147219
initial impl for py2
2017-06-11 16:35:24 -07:00
messense
6b18ccb50b
Implement is_instance and is_subclass ( #27 )
...
* Implement is_instance
* Implement is_subclass
* Move is_instance and is_subclass to Python impl
* Move implementation detail to PyType
2017-06-12 00:41:02 +08:00
messense
cb68cd23a2
Fix some clippy warnings ( #26 )
2017-06-11 23:46:23 +08:00
Nikolay Kim
8188c9533c
do not use descriptor objects for method defs
2017-06-09 15:55:39 -07:00
Nikolay Kim
c28a619efd
add free list support
2017-06-09 14:27:37 -07:00
Nikolay Kim
cfb2b16288
allow to override class name #14
2017-06-09 12:30:13 -07:00
Nikolay Kim
ea8f11fa6d
refactor PyTypeObject trait
2017-06-08 14:34:29 -07:00
Nikolay Kim
86c20bb139
Change sig of PyIterProtocol.__next__ method #18
2017-06-08 13:43:24 -07:00
Nikolay Kim
9e08d3eec5
simplify class method macros
2017-06-08 13:11:16 -07:00
Nikolay Kim
6204de4a6a
Merge branch 'master' of github.com:PyO3/PyO3
2017-06-08 11:29:52 -07:00
Nikolay Kim
a90c763bc0
add class and static methods #17
2017-06-08 11:29:40 -07:00
messense
e12e98a7c1
Convert some std error types to PyErr ( #22 )
...
* Convert some std error types to PyErr
* Add ToPyErr trait
2017-06-08 09:40:30 +08:00
Nikolay Kim
b3079f759c
use descriptor objects for class methods; use PyNoArgsFunction for methods without args
2017-06-06 21:57:03 -07:00