Skip to content

Commit

Permalink
Fixes #2286 : AttributeError: 'SimpleNamespace' object has no attribu…
Browse files Browse the repository at this point in the history
…te 'cache_tag'
  • Loading branch information
PierreQuentel committed Oct 24, 2023
1 parent c19acd4 commit 6b1735a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
21 changes: 8 additions & 13 deletions www/src/Lib/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __len__(self):
return len(self.keys)

def __repr__(self):
s = ', '.join(f'{k}={self.__dict__[k]}' for k in self.keys)
s = ', '.join(f'{k}={self.__dict__[k]!r}' for k in self.keys)
return f'sys.{self.__class__.__name__}({s})'


Expand Down Expand Up @@ -133,16 +133,9 @@ def set_int_max_str_digits(value):
version = '.'.join(str(x) for x in __BRYTHON__.version_info[:3])
version += " (default, %s) \n[Javascript 1.5] on Brython" \
% __BRYTHON__.compiled_date
hexversion = 0x030800f0 # python 3.8

class _comparable:

def hexversion(self):
try:
return '0%d0%d0%d' % (self.major, self.minor, self.micro)
finally: #probably some invalid char in minor (rc, etc)
return '0%d0000' % (self.major)

def __eq__(self, other):
if isinstance(other, tuple):
return (self.major, self.minor, self.micro) == other
Expand Down Expand Up @@ -213,15 +206,17 @@ def __eq__(self, other):
return self.__dict__ == other.__dict__
return NotImplemented


SimpleNamespace.__module__ = "types"

implementation = SimpleNamespace(
name = 'Brython',
cache_tag = f'cpython-{__BRYTHON__.version_info[0]}{__BRYTHON__.version_info[1]}',
version = version_info,
major = __BRYTHON__.version_info[0],
minor = __BRYTHON__.version_info[1],
micro = __BRYTHON__.version_info[2],
releaselevel = __BRYTHON__.version_info[3],
serial = __BRYTHON__.version_info[4])
hexversion = ((__BRYTHON__.version_info[0] << 24) +
( __BRYTHON__.version_info[1] << 16) +
( __BRYTHON__.version_info[2] << 8))
)

hash_info = make_dataclass('hash_info')(
width = 32,
Expand Down
4 changes: 2 additions & 2 deletions www/src/brython.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ $B.stdlib_module_names=Object.keys($B.stdlib)})(__BRYTHON__)
;
__BRYTHON__.implementation=[3,12,0,'dev',0]
__BRYTHON__.version_info=[3,12,0,'final',0]
__BRYTHON__.compiled_date="2023-10-23 17:57:43.238719"
__BRYTHON__.timestamp=1698076663238
__BRYTHON__.compiled_date="2023-10-24 15:17:58.006629"
__BRYTHON__.timestamp=1698153478006
__BRYTHON__.builtin_module_names=["_aio","_ajax","_ast","_base64","_binascii","_cmath","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre1","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","array","builtins","dis","encoding_cp932","hashlib","html_parser","marshal","math","module1","modulefinder","posix","python_re","python_re1","python_re2","unicodedata"]
;
;(function($B){var _b_=$B.builtins
Expand Down
2 changes: 1 addition & 1 deletion www/src/brython_stdlib.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__BRYTHON__.implementation = [3, 12, 0, 'dev', 0]
__BRYTHON__.version_info = [3, 12, 0, 'final', 0]
__BRYTHON__.compiled_date = "2023-10-23 17:57:43.238719"
__BRYTHON__.timestamp = 1698076663238
__BRYTHON__.compiled_date = "2023-10-24 15:17:58.006629"
__BRYTHON__.timestamp = 1698153478006
__BRYTHON__.builtin_module_names = ["_aio",
"_ajax",
"_ast",
Expand Down
4 changes: 4 additions & 0 deletions www/tests/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,9 @@ def traceFn(frame, event, arg):

assert t == []

# issue 2286
for attr in ['name', 'cache_tag', 'version', 'hexversion']:
assert hasattr(sys.implementation, attr)

# remove trace for next tests
sys.settrace(None)

0 comments on commit 6b1735a

Please sign in to comment.