-
-
Notifications
You must be signed in to change notification settings - Fork 424
GSoC: JSON module, generators and context managers #483
Comments
This project was selected as part of the 2017 GSoC. |
Week 1 status update: I was under impression, that I could easily get JSON.stringify to do the heavy lifting, unfortunately I realize now that is not the case, and since I am adjusting the approach, I also decided to do You can checkout my current work on branch json of my fork: https://github.com/abonie/batavia/commits/json |
Week 2: Then I spent quite some time trying to work out how to properly pass keyword arguments to a class constructor implemented in native code, e.g. for Python code Finally I fixed few minor bugs in my code and covered a number of Again, you can see it all here: https://github.com/abonie/batavia/commits/json Edit: One issue I forgot to mention is with sort_keys, I was going to use |
Week 3: With some pointers from @freakboy3742 I investigated the kwargs issue from last week. I think it requires a wider debate, for now it is still unresolved. I have also started working towards decoding json, here is relevant branch of my fork: https://github.com/abonie/batavia/tree/json_decoding. Unfortunately, next week I may be to busy with exams to achieve week 4 goals. My first priority will be responding to any comments regarding PR #577 and then, when time permits, move forward with decoding. |
Week 4: |
Week 5: |
Week 6: Also to sum up phase one:
|
Week 7: I looked into implementing |
Week 8: I feel like it may be a good idea to add even more tests for generators, so I'll try to provide some if I get any extra time. |
Week 9: I also have a quick, but working solution for splitting |
Week 10: BTW I should explain: Russell suggested that Python 3.6 compatibility would be more worthwhile than |
Week 11: I think it would be good to create separate branches for different Python versions rather sooner than later. edit: regarding EXTENDED_ARG problem, if someone could actually explain why in current implementation we add 4 NOPs here https://github.com/pybee/batavia/blob/master/batavia/VirtualMachine.js#L775 that would be most helpful :) |
Wrap up: Other than that, GSoC 2017 is over and I am pretty happy with work I have accomplished over the summer. Few things from original proposal that are still missing:
Everything else, and a little bit more, is done and merged :) Thank you all very much, it's been a blast 👍 |
Congrats! |
Intro
For my GSoC project I would like to fulfill a few tasks, that include finishing up some of the partially implemented data types, implementing modules from Python standard library that are not yet present in Batavia and providing support for some of the language constructs.
I will present my proposed schedule broken down into 3 phases, each roughly a month long. Each task will be described in detail in its phase.
Summarized deliverables:
json
module (with two minor caveats explained below)yield from
statementwith
statementcontextlib
module (reused from CPython)Phase 1 (June)
Tasks:
dict
andlist
data typesFull disclosure: June is the last month of summer semester at my university, so I will be able to commit 18+ hours per week in Phase 1, but definitely not full-time. That is why I am reaching for relatively low hanging fruits here, and proposing more challenging tasks in phases 2 & 3.
Why:
Dicts and lists are two most commonly used containers in Python. As it stands, their Batavia implementation is functional, but incomplete. Following methods are not properly implemented:
pop
,popitem
,setdefault
,fromkeys
whilekeys
,values
anditems
return type is incosistent with Python's reference documentation and__len__
is buggedinsert
andremove
and does not handle arguments passed topop
JSON is the prevailing data format for browser/server communication. Obviously Batavia will need to support encoding and decoding between JSON representation and Python objects and that is what
json
module from standard library does.Together these two changes will greatly increase convenience of manipulating and sending data.
How:
I will make use of JavaScripts builtin JSON object and its
parse
andstringify
methods to provide native implementation conforming to API of Python'sjson
module. This comes with few caveats:stringify
it is not possible to disable circularity check while encoding an object to JSON. Therefore this implementation will ignorecheck_circular
argument passed to corresponding methods.stringify
as a generator producing encoding in chunks "on the fly". As a resultiterencode
method ofJSONEncoder
will always return one whole chunk.This is not ideal, however it will still be consistent with Python's API
Schedule:
Week 1: Implement
dict
andlist
methods listed aboveWeek 2:
json.dump
,json.dumps
Week 3:
json.JSONEncoder
Week 4:
json.load
,json.loads
Week 5:
json.JSONDecoder
,json.JSONDecodeError
Phase 2 (July)
Tasks:
yield from
statementwith
statementWhy:
Context managers are objects that allow creating runtime context in which body of the
with
statement is executed. In my mind they are a great feature of Python language as they encourage writing safe programs, by being easier to work with in many aspects thantry
/finally
statements. Currently there is no support forwith
statement in Batavia.Generators in turn are an enigmatic concept in Python, that evolved into fully fledged coroutines. Complete support for generators is important to begin work on asyncio in the future, but also to provide full support for context managers. At this point Batavia does not support
yield from
statement, which greatly simplifies working with generators and current implementation of generators needs fixing (in particular close and throw do not work properly)Schedule:
Week 6: Fix bugs in generators
Week 7 & 8: Handle YIELD_FROM opcode in Batavia's Python VM
Week 9 & 10: Handle opcodes SETUP_WITH and WITH_CLEANUP in VM
Phase 3 (August)
Tasks:
with
statementcontextlib
module from Python standard libraryWhy:
I have already described the benefits of
with
statements in previous phase.contextlib
provides utilities for working with them, e.g. multiple context managers implementation and decorators for creating context managers.CPython's
contextlib
is written in pure Python. It should be relatively straightforward to reuse that implementation. It does make few imports:sys.stdout
/in
which are already implemented in Bataviasys.exc_info
which will require native implementationfunctools.wraps
again, this has Python implementation that could be reusedcollections.deque
however it is used as a simple stack, so could be replaced by a Python listSchedule:
Week 11: Complete work on SETUP_WITH/WITH_CLEANUP
Week 12: For Python 3.5+ break down WITH_CLEANUP into WITH_CLEANUP_START and _FINISH, provide implementation that will work for
async with
in the futureWeek 13: Implement "dependencies" for
contextlib.py
Week 14: Incorporate CPython's
contextlib
into BataviaThe text was updated successfully, but these errors were encountered: