Closed csboling closed 8 years ago
The 2.7 build is failing because testing the async/await code relies on the pytest-asyncio plugin, which doesn't work in 2.7. The build passes for 2.7 with Tox on my local machine, but I'm not sure how to get Travis to install a testing dependency only for some versions.
These commits make the following changes to the code, reflecting them in the tests and docs.
Promise.fulfilled
/resolve
,Promise.rejected
, andPromise.all
were converted fromstaticmethod
s toclassmethod
s, allowing them to invoke constructors and otherclassmethod
s viacls()
andcls.<method>
rather thanPromise()
andPromise.<method>
. Additionally class atttributes are now referenced usingself.<attribute>
rather thanPromise.<attribute>
. This improves support for classes which inherit fromPromise
, since if client code defines a subclassSpecialPromise
then calling e.g.SpecialPromise.all
orSpecialPromise().then()
will now return aSpecialPromise
instance rather than aPromise
instance.promisify
andpromise_for_dict
were made intoclassmethod
s rather than free functions for the same reason. To preserve API compatibility we also aliaspromisify = Promise.promisify
andpromise_for_dict = Promise.promise_for_dict
. Parameterized test fixtures were added to run tests against both the classmethod and the free function versions.__iter__
and__await__
methods were added to let Python 3.4 and 3.5 codeyield from
orawait
aPromise
in asynchronous code. This makes working withPromise
s feel more native when usingasyncio
and aligns with ES7'sasync
/await
behavior for native promises. I have not tried to test this against the backportedasyncio
library for Python 3.3 but it should work fine since new syntax is not used anywhere in the library, only in tests.conftest.py
was added to skip tests involving the async/await behavior on Python versions that do not support it.Promise.promise_for_dict
was added to the documentation, with a description directly copied from its docstring.Promise
is calledPromise.rejected
rather thanPromise.reject
-- the latter is an instance method.