Skip to content

Commit

Permalink
Fixes #558 : a set isn't properly cloned by "a = set(b)" statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Quentel committed Feb 6, 2017
1 parent 1393955 commit 143d246
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions www/src/brython.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $B.regexIdentifier=/^(?:[\$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C
__BRYTHON__.implementation=[3,3,1,'alpha',0]
__BRYTHON__.__MAGIC__="3.3.1"
__BRYTHON__.version_info=[3,3,0,'alpha',0]
__BRYTHON__.compiled_date="2017-02-05 21:43:42.821780"
__BRYTHON__.compiled_date="2017-02-06 15:25:19.796403"
__BRYTHON__.builtin_module_names=["posix","sys","errno","time","_ajax","_base64","_jsre","_multiprocessing","_posixsubprocess","_profile","_svg","_sys","builtins","dis","hashlib","json","long_int","math","modulefinder","random","_abcoll","_codecs","_collections","_csv","_functools","_imp","_io","_random","_socket","_sre","_string","_struct","_sysconfigdata","_testcapi","_thread","_warnings","_weakref"]

;(function($B){var js,$pos,res,$op
Expand Down Expand Up @@ -9763,7 +9763,7 @@ $SetDict.__format__=function(self,format_string){return $SetDict.__str__(self)}
$SetDict.__ge__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){return !$SetDict.__lt__(self,other)}else{return _b_.object.$dict.__ge__(self,other)}}
$SetDict.__gt__=function(self,other){if(_b_.isinstance(other,[set,frozenset])){return !$SetDict.__le__(self,other)}else{return _b_.object.$dict.__gt__(self,other)}}
$SetDict.__init__=function(self){var $=$B.args('__init__',2,{self:null,iterable:null},['self','iterable'],arguments,{iterable:[]},null,null),self=$.self,iterable=$.iterable
if(_b_.isinstance(iterable,[set,frozenset])){self.$items=iterable.$items
if(_b_.isinstance(iterable,[set,frozenset])){self.$items=iterable.$items.slice()
return $N}
var it=_b_.iter(iterable),obj={$items:[],$str:true,$num:true}
while(1){try{var item=_b_.next(it)
Expand Down
6 changes: 3 additions & 3 deletions www/src/brython_dist.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion www/src/py_VFS.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions www/src/py_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ $SetDict.__init__ = function(self){
['self', 'iterable'], arguments, {iterable:[]}, null,null),
self = $.self, iterable= $.iterable

if(_b_.isinstance(iterable,[set,frozenset])){
self.$items = iterable.$items
if(_b_.isinstance(iterable,[set, frozenset])){
self.$items = iterable.$items.slice()
return $N
}
var it = _b_.iter(iterable),
obj = {$items:[],$str:true,$num:true}
obj = {$items:[], $str:true, $num:true}
while(1){
try{
var item = _b_.next(it)
$SetDict.add(obj,item)
$SetDict.add(obj, item)
}catch(err){
if(_b_.isinstance(err, _b_.StopIteration)){break}
throw err
Expand Down Expand Up @@ -533,10 +533,10 @@ function set(){
// $str is true if all the elements in the set are string, $num if
// all the elements are integers
// They are used to speed up operations on sets
var res = {__class__:$SetDict,$str:true,$num:true,$items:[]}
var res = {__class__:$SetDict,$str:true, $num:true, $items:[]}
// apply __init__ with arguments of set()
var args = [res].concat(Array.prototype.slice.call(arguments))
$SetDict.__init__.apply(null,args)
$SetDict.__init__.apply(null, args)
return res
}
set.__class__ = $B.$factory
Expand Down
2 changes: 1 addition & 1 deletion www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__BRYTHON__.implementation = [3, 3, 1, 'alpha', 0]
__BRYTHON__.__MAGIC__ = "3.3.1"
__BRYTHON__.version_info = [3, 3, 0, 'alpha', 0]
__BRYTHON__.compiled_date = "2017-02-05 21:43:42.821780"
__BRYTHON__.compiled_date = "2017-02-06 15:25:19.796403"
__BRYTHON__.builtin_module_names = ["posix","sys","errno", "time","_ajax",
"_base64",
"_jsre",
Expand Down
6 changes: 6 additions & 0 deletions www/tests/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,12 @@ def __float__(self):
assert sin(num) == -0.9165215479156338
assert log(num) == 3.7376696182833684

# issue 558
a = set([5, 10])
b = set(a)
a.difference_update([5])
assert a == {10}
assert b == {5, 10}

# ==========================================
# Finally, report that all tests have passed
Expand Down

0 comments on commit 143d246

Please sign in to comment.