breaking changes
python 2 incorrectness:
long
- when adding two long objects the result is likely to be an
int
- when adding two long objects the result is likely to be an
method
- unbound methods are no longer supported
- The
base
class for all type objects will beobject
even if the base class is not specified
skulpt api
Sk.builtin.object.prototype.genericGetAttr
->Sk.generic.getAttr
Sk.builtin.object.prototype.genericSetAttr
->Sk.generic.setAttr
Sk.builtin.typeLookup
removedbiginter.js
replaced by the jsbi librarySk.abstr.inherits
removed - inheritance exclusively dealt with bySk.abstr.setUpInheritance
Sk.misceval.objectRepr
returns a js string (previouslySk.builtin.str
)Sk.__future__.python3
becomes the default. Those wishing to usepython2
must define this in theSk.configure
object.
slot changes
mp$length
replaced bysq$length
in the codebasesq$ass_item
/sq$ass_slice
replaced withmp$ass_subscript
nb$nonzero
replaced withnb$bool
and switch version takes care of mapping the appropriate dunder method.mp$del_subscript
replaced bymp$ass_subscript
(as per Cpython)- deleting vs setting an item is based on the call signature
mp$ass_subscript(key, value)
-> set itemmp$ass_subscript(key)
-> delete item
- If a dunder func is defined on a user defined class then the slot function is guaranteed.
- e.g.
__len__
defined guaranteessq$length
. - A slot function defined by skulpt in this way throws the appropriate errors and converts the return value to the appropriate object.
sq$length
:__len__
is called usingSk.misceval.callsim(OrSuspend)Array
.- The result is checked to be an
int
and then converted tonumber
sincesq$length
expects anumber
.
- e.g.
tp$str
removed from some builtins as per Python 3.8 changes- If
tp$richcompare
is defined - wrapper functionsob$eq
etc are created during - this waySk.misceval.richCompareBool
need only check for the existance of anob$*
slot.- in fact - the existance of these slots is guaranteed since they are inherited from
Sk.builtin.object
- in fact - the existance of these slots is guaranteed since they are inherited from
tp$mro
/tp$bases
are Js Arrays rather thanSk.builtin.tuple
tp$str
and$r
for errors were changed as per Cpython.
flags
sk$acceptable_as_base_class
used for some type objectssk$object
every skulpt object inherits this flag fromSk.builtin.object
hp$type
all instance ofsk$klass
klassessk$basetype
all native classes that inherit fromobject
sk$prototypical
do we need to walk up the MRO or can we just check theprototype
other internal changes
- the use of
numPromoteFunc
was removed for performance improvements in the implementation ofSk.asbtr.numberBinOp
- It was performance beneficial to leave the promoting to the respective
nb$
slots int
binop slots only deal with instance ofint
float
binop slots deal with instances offloat
andint
complex
binop slots deal with instances ofcomplex
,float
andint
- It was performance beneficial to leave the promoting to the respective
set
andfrozenset
now share much of their implementationcollections
module rewritten using new apiitertools
module rewritten using new api - these are now type objects rather than instances ofgenerator
dict
andset
throw errors if the objects change size during iteration as per Cpython.Sk.builtin.check*
moved tosrc/check.js
enumerate
/filter_
/reversed
/zip_
/map_
combined into one filesrc/iteratorobjects.js
tuple_iter_
/str_iter_
etc combined intosrc/simple_iterators.js
dictviews
likedict_items
etc moved tosrc/dictviews.js
number.js
removednumtype.js
removedseqtype.js
removedSk.builtin.check*
moved tosrc/check.js
mp$subscript
should not be called by a js object (see changes inrandom.js
)
call signatures of builtins
new
is required for (almost) all builtin types- 3 exceptions -
Sk.builtin.bool
,Sk.builtin.none
,Sk.builtin.NotImplemented
- These 3 will always return their respective constant(s) and are thus not required to be used as constructors.
- 3 exceptions -
- Restricted parameters for directly accessing a constructor of an
Sk.builtin
type
type | params | notes |
---|---|---|
Sk.builtin.int_ |
`{number | JSBI (bigint) |
Sk.builtin.float_ |
{number} |
|
Sk.builtin.complex |
{number, number} |
|
Sk.builtin.list |
{Array=} |
|
Sk.builtin.tuple |
{Array=} |
|
Sk.builtin.set |
{Array=} |
|
Sk.builtin.dict |
{Array=} |
key/value pairs - only pyObjects |
Sk.builtin.str |
{*} |
can be used to convert a pyObject |
Sk.builtin.bool |
{*} |
can be used to convert a pyObject |
Major changes
- All type objects are now callable using their respective
tp$call
methods inherited fromSk.builtin.type
- All native type objects will require a
tp$new
andtp$init
method (maybe inherited bySk.builtin.object
) - All type objects are javascript instances of
Sk.builtin.type
- All single inherited objects follow javascript inheritance
- All native type objects now have the following and replaces the use of
Sk.builtin.function
for all dunder function/methods.wrapper_descriptors
akaslot_wrappers
method_descriptors
classmethod_descriptors
getset_descriptors
akaattributes
/member_descriptors
Sk.builtin.sk_method
is an alternative toSk.builtin.function
and is used by the abovedescriptor
types- mangled names are never passed to the user but instead are an attribute on
Sk.builtin.str
instances as$mangled
mappingproxy
added$d
removed on all type objects.attributes
of a type object now only appear on theprototype
. Previously these appeared on both thetype
object and theprototype
Additions
dict
,tuple
are suspendableclassmethod
,property
,staticmethod
have native skulpt implementationssuper
can now be unboundSk.builtin.func
objects gain aqualname
in compile code- API for building native types
Sk.abstr.buildNativeClass
range_iterator
class addedreverse
iterators added forlist
,dict_views
,range
sk$asarray
used by types to convert to a javascript array.
Sk.abstr.
buildNativeClass
buildIteratorClass
setUpBuiltinMro
setUpMethods
setUpGetSets
setUpSlots
setUpClassMethod
setUpBaseInheritance
setUpModuleMethod
checkNoKwargs
checkNoArgs
checkOneArg
checkArgsLen
copyKeywordsToNamedArgs
Sk.generic.
getAttr
setAttr
selfIter
iterator
new
newMethodDef
iterNextWithArray
iterNextWithArrayCheckSize
iterLengthHintWithArrayMethodDef
iterReverseLengthHintMethodDef
getSetDict
Sk.misceval.
asIndexOrThrow
arrayFromIterable
- optional canSuspend implementation that returns an array from a python iterator
slotdefs.js
- contains all the information about mapping slots to dunders and vice versa.