Closed Almenon closed 4 years ago
Here is an overview of what got changed by this pull request:
Issues
======
+ Solved 2
- Added 2
Complexity decreasing per file
==============================
+ python/arepl_python_evaluator.py -3
See the complete overview on Codacy
import sys
import importlib
x = [k for k in sys.modules]
# from decimal import Decimal, getcontext
import decimal
# importlib.reload(decimal)
print(decimal.Decimal("1.6") ** decimal.Decimal("1.6")) # first run: 2.121.... second run: 2.1
decimal.getcontext().prec = 2 # changes precision
print(decimal.Decimal("1.6") ** decimal.Decimal("1.6")) # first run: 2.1 second run: 2.1
del sys.modules['decimal']
^ this is with currentl arepl version
Deleting decimal from modules doesn't help fix the problem 😱
It's because decimal stores values in the context and that doesn't get wiped out when reloading a module.
I can't clear the context but I can run code inside a empty context each time like so:
# earlier on:
run_context = contextvars.Context()
global run_context
if not exec_args.usePreviousVariables:
# reset context for fresh run
run_context = contextvars.Context()
run_context.run(exec, exec_args.evalCode, eval_locals)
Docs: https://docs.python.org/3/library/contextvars.html#contextvars.Context https://www.python.org/dev/peps/pep-0567/
Note that context vars was introduced in python 3.7 so for 3.6 I need to use threading.local
somehow. Or maybe just not support 3.6 screw it
https://github.com/python/cpython/blob/master/Lib/_threading_local.py
Note that context vars was introduced in python 3.7 so for 3.6 I need to use threading.local somehow. Or maybe just not support 3.6 screw it
3.6 isn't EOL until 23 Dec 2021 so preferably I would keep it around https://endoflife.date/python
I tried accessing the thread local vars in 3.6 but I couldn't find them, python raised a attributeerror :(
I guess I'll just "officially" drop support for 3.6 but use a if/else so python 3.6 doesn't totally break with arepl
3.6 is only a minority of AREPL users:
customEvents | where name == 'almenon.arepl/closed' | summarize test=count(tostring(timestamp)) by tostring(customDimensions.pythonVersion)
https://i.imgur.com/FbB1OWY.png
(full data not shown)
:tada: This PR is included in version 1.3.12 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
fixes #134