Comments (6)
Has any further bug-fix progress been made ?
I had issues with python 3.10 and reloadr.
from reloadr.
Looks like Python 3.9 changes the way it handles classes internally.
I can reproduce the issue using Python 3.9 on Linux using Docker image python:3.9-buster
. The example works fine using Python 3.8 via python:3.9-buster
.
Traceback:
$ python 01_manual_reload.py
Car on 1001 3001
Traceback (most recent call last):
File "reloadr/examples/01_manual_reload.py", line 28, in <module>
Car._reload()
File "/usr/local/lib/python3.9/site-packages/reloadr.py", line 136, in _reload
instance.__class__ = self._target
TypeError: __class__ must be set to a class, not 'ClassReloadr' object
from reloadr.
The issue comes from https://github.com/hoh/reloadr/blob/master/reloadr.py#L31 : in Python 3.9, inspect.getsource(class_object)
returns the decorators as well.
Below is a temporary patch. The issue of decorators should be handled in a better way.
- if kind == 'def':
- # `inspect.getsource` will not return the decorators in the source of classes,
- # but will return them in the source of functions.
- source = source.replace("@autoreload\n", "")
+ source = source.replace("@autoreload\n", "").replace("@reloadr\n", "")
from reloadr.
@hoh If a regex approach is OK to remove all the decorators that follow @reloadr, then I can take this on me. I'd try to find time this week to work on it.
I'd be looking to add a test for get_new_source
function (I'm familiar with pytest, but maybe you prefer something else?), and maybe something like tox (maybe you have better recommendations) to test it with different python versions. Could add GHA to run the test and add new python versions to test with - to make sure future versions wouldn't break it, this function.
from reloadr.
Hi @P6rguVyrst ,
The regex approach looks fine. It would be wise to also include the following names as aliases of that decorator:
@reloadr
@autoreload
@reloadr.reloadr
@reloadr.autoreload
Testing using Pytest sounds wise. Regarding the matrix of Python versions, either Tox or GitHub Actions seem fine. I would prefer the change that fixes this issue and a simple test in one PR, and the addition of Tox, GitHub Actions, ... in another since that is not entirely related.
from reloadr.
It would be wise to also include the following names as aliases of that decorator
Took me a while, but I think I see what you mean.
Do you mean that the solution should not be limited to @reloadr
only, but cover any one of those interfaces that are currently supported by the library.
decorator_scope = [
"@reloadr",
"@autoreload",
"@reloadr.reloadr",
"@reloadr.autoreload",
]
Makes it a more interesting problem, but wouldn't mind giving a go extending my initial solution and try to come up with a more complete solution.
Technically speaking something like r"(@reloadr|@autoreload)(.*)(?=class)"
should cover any functions in the reloadr module has + the from reloadr import autoreload
from reloadr.
Related Issues (11)
- Reloading from Jupyter Notebooks is not supported HOT 2
- Errors with simple script HOT 3
- Python3 syntax not supported due to baron not handling it HOT 3
- error with reloading a subclass HOT 1
- reload function which is inside another function HOT 2
- Consider using wrapt to wrap reloader classes
- Parent classes cannot be reloaded HOT 4
- Trigger reloader from somewhere else. HOT 7
- Auto reloads are incompatible with gevent HOT 1
- How can I auto reload all the involved modules when the source is changed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reloadr.