-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Discussion of Python 3.5 support #1329
Comments
We "by definition" have "%-formatting for binary strings", I'm not sure however what details PEP 461 may have. |
is potentially interesting, because it's boring to handle it in each app, and actually nobody handles it in each app, unless faces issues, and then it's likely users, and not an author. So, doing that PEP kinda saves from such situations. But then again it may be just adding more bloat than necessary. Need to read PEP, and actually, all PEPs (in detail, again, or at all). |
We are missing: "%b" for interpolating bytes objects, "%a" for repr of bytes, "%c" in uPy truncates to 7-bit char but should be full 8-bit char, and we don't support % operator on bytearray object. |
Type hints sound like they could be useful. Personally I'd like to see unpacking generalizations and async/await support. |
I just had a read of that PEP and it looks like it might be some effort, and a decent increase in code size, to implement that. It allows things like |
Running uPy testsuite against CPython3.5b3 produces few warnings/errors. |
A few too many, or few enough to easily fix them? Do you have any examples of failures? |
I built 3.5b3, and that managed to install itself as system-wide python3, so I scratched ny head for a bit while testsuite fails. As soon as I figured that out, I switched it back and didn't look back, and don't think it's a priority before 3.5 release. So, just FYI ;-). |
3.5.0 was released today. |
CPy 3.5 is now distributed with Arch Linux so that's what I'll be using. There are only a few errors (mostly related to new , * syntax). |
@pfalcon you'll be pleased to know that regex splitting with an empty regex is on track for deprecation. Running tests/extmod/ure_split.py with CPy 3.5 gives a FutureWarning for these cases. So this means the dirty magic is hopefully gone! |
Tests now pass with CPy 3.5; see 34f26ea. |
Evaluation order of dictionary key/value pairs in CPy 3.5 has changed. Key is now evaluated first in a dict literal. |
Hi, |
@njouanin await/async syntax is not (yet) supported. But the underlying "yield from" functionality is. |
More specifically, await/async syntax was initially-prototyped by @dpgeorge, but received the same cool response as the original CPython await/async (during discussion, a lot of people said "we don't need it"). When every 2nd Python programmer will use await/async, we surely will implement it, but now, when it's perhaps every 100000th, why bother. |
i just saw coreio posted - which is based on await/async. I need to look at it closer to understand it, but it sounds like something like it would be usefiul. I need to figure out if something equivalent can be done using what we have (uasyncio). |
It can be, no worries - all this async/await is just syntactic sugar over yield. It wouldn't be a problem, but it was made deliberately incompatible with classical yield, and that's what I don't like for example. |
0bb57bf shows some motion towards PEP 475 compliance (but I don't plan to do much of that, and the whole matter is quite depressing). |
I'm not sure how «big» is new async/await syntax for micropython, but for desktop python it does a lot (finalizing and readability at most):
Most of python programmers still use python 2, btw. Not because python 2 is better, but they have same arguments. |
And that's exactly the problem with implementing it - it's easy to add "await" as an alias for "yield from", it's much harder to implement async with and for. For that, someone needs to actually understand how it works and what are its limits. I don't think many people in the whole world care to do that.
And they're right, and its duty of Python3 drivers to make it attractive for people. Adding new useful features is a way to do that, and churning out bunch of features of unknown usability isn't. So, everyone does its job - MicroPython makes as small as possible Python implementation to deepen Python outreach, and CPython works on providing useful features which are to be proven actually used. Bottom line: if you're interested to provide full async/await implementation, you're certainly welcome too ;-). |
I think they just call/async-call magic methods. |
I'm afraid, I have not enough skills for that. At first, I don't familar with micropython internals. |
See #1690. |
#2015 proposes to bump "supported language" in README to 3.5, now that "async" keyword was implemented. |
It is a nice feature though.. For 3.5 the things I already wished we had multiple times are PEP 448 - additional unpacking generalizations and PEP 485 - math.isclose(). |
I would like to get MicroPython to a point where we can claim that it implements Python 3.5, at least the syntax (so it can parse any valid Python 3.5 code). And the main blocker to that is PEP 448 (unpacking generalisations). I looked into it it depth some time ago and came to the conclusion it was not easy, required new bytecodes, and a fair amount of extra code to handle these generalisations. But probably now is a good time to revisit it and make a proof of concept patch to see exactly what is required for that feature. Then make a decision about it. Apart from that, I don't see any reason not to include features of more recent Python if they are useful and in demand (eg like underscores in numeric literals).
It looks ok for a PR, to further discuss it. Is it an original implementation (not copied from CPython)? Also might want to use |
If it's not too problematic PEP448 would be useful. There is evident demand: I've already had to explain to users that it's not yet supported. I appreciate that PEP572 is Python 3.8. My interest is on the theory that it might improve performance and/or code size e.g. in comprehensions and lambdas. |
Same here! It'll come anyway so it might be as well available in time with the release of 3.8 |
Notwithstanding the fact that FWIW, I've have ended up implementing a tiny linear algebra system on uPy (they are handy for optimising some dynamic systems and the ESP32 with SPIRAM has the space and horsepower to cope) and having the (I also note that MicroPython already supports |
@nickovs I have already implemented this in #4740 (I am working on porting a useful subset of numpy, based on ublas/lapack like regular numpy). |
PEP 465 can be crossed off of the list now |
proposed PEP 475 implementation in #5723 |
Should PEP 485 be crossed off of the list? #4894 |
Yes, list is now updated for PEP 475 and 485. |
hey guys |
please help me by contacting at telegram on @Kabraji0 |
Now that #5807 has been merged, we have partial support for PEP 448, namely:
The remaining bit that is not implemented is:
I think we could leverage the partial implementation to easily implement the rest. It could work like this:
|
That's interesting, and definitely simple... but I'm not sure how to implement intrinsic functions (efficiently). I wonder how CPython does it, do they create a comprehension function to build the tuple/list/set/dict? If so that would alter the semantics. |
I looked at the patch that implements it and they just added new opcodes for each case: +#define BUILD_LIST_UNPACK 149
+#define BUILD_MAP_UNPACK 150
+#define BUILD_MAP_UNPACK_WITH_CALL 151
+#define BUILD_TUPLE_UNPACK 152
+#define BUILD_SET_UNPACK 153 |
I guess we could do that as well. I think this feature is rarely used (??) so if MicroPython implements it I would say it should be done as "cheaply" as possible, ie with a minimum of firmware size. Maybe adding new opcodes is the smallest way to implement it, or maybe it's some other way. It looks like the hardest thing (biggest increase in code size) would be to change the compiler to detect these cases. So investigations would be best to start there. |
MicroPython aims to implement the Python 3.x "standard". At the moment x is currently 4, ie we try to be compatible with CPython 3.4. It's new territory as to what to do when CPython evolves to larger version numbers. I would say we should try to follow the changes and implement them when possible/sensible.
Python 3.5 had a feature freeze on 24 May 2015 and is scheduled for final release on 13 September 2015. This ticket here is about discussing if, what and how we should upgrade uPy to version 3.5 of the language. It may be that some issues need to break off into separate tickets and that's fine but we should link to them from this one.
The PEP discussing the new features in 3.5: https://www.python.org/dev/peps/pep-0478/
A more friendly overview in the docs: https://docs.python.org/3.5/whatsnew/3.5.html
Below is a list of finalised/accepted PEPs for 3.5 grouped into their impact to MicroPython.
Extensions to the syntax:
Extensions and changes to the runtime:
Standard library changes:
Miscellaneous changes that are not relevant to MicroPython:
Other Language Changes
"namereplace"
error handlers. The"backslashreplace"
error handlers now work with decoding and translating.New modules
Changes to MicroPython built-in modules
isclose()
provides a way to test for approximate equality.OrderedDict
class is now implemented in C, which makes it 4 to 100 times faster.OrderedDict.items()
,OrderedDict.keys()
,OrderedDict.values()
views now supportreversed()
iteration.index()
,insert()
, andcopy()
, and supports the + and * operators.namedtuple()
can now be updated.UserString
class now implements the__getnewargs__()
,__rmod__()
,casefold()
,format_map()
,isprintable()
, andmaketrans()
methods to match the corresponding methods ofstr
.merge()
can now be customized by passing a key function in a new optional key keyword argument, and a new optionalreverse
keyword argument can be used to reverse element comparisonBufferedIOBase.readinto1()
method, that uses at most one call to the underlying raw stream'sRawIOBase.read()
orRawIOBase.readinto()
methods.JSONDecodeError
instead ofValueError
to provide better context information about the error.inf
andnan
.isclose()
provides a way to test for approximate equality.gcd()
function has been added. Thefractions.gcd()
function is now deprecated.scandir()
function returning an iterator ofDirEntry
objects has been added.urandom()
function now uses thegetrandom()
syscall on Linux 3.17 or newer, and getentropy() on OpenBSD 5.6 and newer, removing the need to use /dev/urandom and avoiding failures due to potential file descriptor exhaustion.get_blocking()
andset_blocking()
functions allow getting and setting a file descriptor's blocking mode (O_NONBLOCK.)os.path.commonpath()
function returning the longest common sub-path of each passed pathname.sub()
andsubn()
functions now replace unmatched groups with empty strings instead of raising an exception.re.error
exceptions have new attributes,msg
,pattern
,pos
,lineno
, andcolno
, that provide better context information about the errorsocket.sendfile()
method allows sending a file over a socket by using the high-performanceos.sendfile()
function on UNIX, resulting in uploads being from 2 to 3 times faster than when using plainsocket.send()
.socket.sendall()
method no longer resets the socket timeout every time bytes are received or sent. The socket timeout is now the maximum total duration to send all data.socket.listen()
method is now optional. By default it is set to SOMAXCONN or to 128, whichever is less.SSLSocket.version()
method to query the actual protocol version in use.SSLSocket
class now implements aSSLSocket.sendfile()
method.SSLSocket.send()
method now raises either thessl.SSLWantReadError
orssl.SSLWantWriteError
exception on a non-blocking socket if the operation would block. Previously, it would return 0.cert_time_to_seconds()
function now interprets the input time as UTC and not as local time, per RFC 5280. Additionally, the return value is always an int.SSLObject.shared_ciphers()
andSSLSocket.shared_ciphers()
methods return the list of ciphers sent by the client during the handshake.SSLSocket.do_handshake()
,SSLSocket.read()
,SSLSocket.shutdown()
, andSSLSocket.write()
methods of theSSLSocket
class no longer reset the socket timeout every time bytes are received or sent.match_hostname()
function now supports matching of IP addresses.set_coroutine_wrapper()
function allows setting a global hook that will be called whenever a coroutine object is created by an async def function. A correspondingget_coroutine_wrapper()
can be used to obtain a currently set wrapper.is_finalizing()
function can be used to check if the Python interpreter is shutting down.monotonic()
function is now always available.(Changes to non-built-in modules will need to be documented elsewhere.)
The above list should be edited if/when progress is made on a given feature.
The text was updated successfully, but these errors were encountered: