Comments (11)
Without having had a look at any of the involved code, I assume this is due to the decorator misbehaving, ie, not using something like https://docs.python.org/3/library/functools.html#functools.wraps or functools.update_wrapper
from smart_importer.
thank you, yes that is the problem. Currently, the decorator returns a a subclass of the original importer. The subclass overwrites the extract method. Hence the modified class name of the decorated importer.
Any ideas how I could patch the importer class (i.e., replace its extract method) while preserving its class name?
from smart_importer.
Any ideas how I could patch the importer class (i.e., replace its extract method) while preserving its class name?
Why is the decorator applied to the whole class? Can't it just be a decorator that applies to the extract method if that's all you need to patch?
from smart_importer.
The motivation was that this would make it easier to apply the decorator, see #9.
Instead of having to write a custom importer just to be able to apply the decorator, like this:
class MyCustomCSVImporter(CsvImporter):
@SmartImportDecorator(whatever, arguments)
def extract(file, existing_entries=None):
return super().extract(file, existing_entries)
CONFIG = [
MyCustomCSVImporter(whatever, arguments)
]
...it would be more convenient to simply apply the decorator to the whole importer class. This could even be done inline in the import config file, like this:
CONFIG = [
SmartImportDecorator(CsvImporter(whatever, arguments))
]
from smart_importer.
It might then be easier to implement it as a function decorator and have the class decorator overwrite the extract method instead of subclassing it.
from smart_importer.
Ok thanks!, I'll give it a try. In pseudocode:
if (decorator was applied to extract method):
wrap the extract method using functools.wraps
return the wrapped method
else if (decorator was applied to an importerClass):
wrap the extract method using functools.wraps
importerClass.extract = the freshly wrapped extract method
return the patched importerClass
from smart_importer.
Update: This task turned out to be more complex than I thought. I have been fighting with nested structures of python decorators. Also with different behaviors depending on how decorators are applied (with or without parentheses, to a class vs to a method). I gave the wrapt
library a try and also tried a DIY solution. I guess I'll just keep trying.
from smart_importer.
Ok, I got it working now. Works in fava, passes all unit tests, merged into master.
from smart_importer.
ps
sorry for bypassing the pull request mechanism this time. I could not get the merge working through the web GUI... The problem then turned out to be simply that my github session was expired. Anyway, I pushed the merge into the master branch. All unittests work, my personal importers work, and @tarioch I hope it will also work fine for you!
from smart_importer.
Works for me without change :) I'm not using them as annotations but instead instantiate them manually in my import.config
from smart_importer.
ok great, thank you for the feedback!
from smart_importer.
Related Issues (20)
- pylint fails, tox depends on wrong version of beancount? HOT 3
- Expose ImporterHook interface HOT 4
- Allow custom getters for attributes HOT 2
- Predict postings with amounts HOT 3
- Predict metadata (and tags) HOT 3
- Package working with python 3.6.12 but not with python 3.9 HOT 26
- ImportError undefined symbol _PyGen_Send HOT 2
- Unable to use smart_importer with beangulp Importers HOT 8
- release a v0.4 to pypi HOT 2
- How to pass in existing entries as training data other than the current bean file HOT 10
- Using `file_account()` to filter training data doesn't work for certain use cases HOT 4
- TAGS HOT 2
- Predictions might lead to original posting being switched to 2nd place after prediction HOT 1
- Smart importer give duplicate asset postings
- Checker for potential mistakes HOT 1
- Passing too many arguments to extract() HOT 1
- I can't manage to have smart_importer working HOT 6
- Remove suggestions because suggest=True adds list as metadata which is invalid HOT 7
- Bypass specific transactions. HOT 4
- please provide the hook helpers as an own package HOT 2
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 smart_importer.