dkpro / dkpro-cassis

UIMA CAS processing library written in Python
https://pypi.org/project/dkpro-cassis/
Apache License 2.0
85 stars 22 forks source link

Typesystem loading fails if features contain features called self #90

Closed jcklie closed 5 years ago

jcklie commented 5 years ago

Describe the bug Typesystem loading fails if features contain features called self

To Reproduce Steps to reproduce the behavior:

  1. Add a feature called self

Expected behavior No error occurs

Error message

Traceback (most recent call last):
  File "C:/Users/x/PycharmProjects/dkpro-cassis/tests/load_wex_ts.py", line 12, in <module>
    typeSystem = load_typesystem(ts_descriptor_file)
  File "C:\Users\x\PycharmProjects\dkpro-cassis\cassis\typesystem.py", line 538, in load_typesystem
    return deserializer.deserialize(source)
  File "C:\Users\x\PycharmProjects\dkpro-cassis\cassis\typesystem.py", line 641, in deserialize
    t, name=f.name, rangeTypeName=f.rangeTypeName, elementType=f.elementType, description=f.description
  File "C:\Users\x\PycharmProjects\dkpro-cassis\cassis\typesystem.py", line 480, in add_feature
    type_.add_feature(feature)
  File "C:\Users\x\PycharmProjects\dkpro-cassis\cassis\typesystem.py", line 242, in add_feature
    self.__attrs_post_init__()
  File "C:\Users\x\PycharmProjects\dkpro-cassis\cassis\typesystem.py", line 175, in __attrs_post_init__
    self._constructor = attr.make_class(name, fields, bases=(FeatureStructure,), slots=True, eq=False, order=False)
  File "C:\Users\x\Anaconda3\lib\site-packages\attr\_make.py", line 2129, in make_class
    return _attrs(these=cls_dict, **attributes_arguments)(type_)
  File "C:\Users\x\Anaconda3\lib\site-packages\attr\_make.py", line 1002, in wrap
    builder.add_init()
  File "C:\Users\x\Anaconda3\lib\site-packages\attr\_make.py", line 689, in add_init
    self._is_exc,
  File "C:\Users\x\Anaconda3\lib\site-packages\attr\_make.py", line 1351, in _make_init
    bytecode = compile(script, unique_filename, "exec")
  File "<attrs generated init cassis.typesystem.com_ibm_es_tt_DocumentMetaData-19>", line 1
SyntaxError: duplicate argument 'self' in function definition

Process finished with exit code 1

Additional context

The issue occurs because we attempt to create a class with a field called self which is reserved in Python.

jcklie commented 5 years ago

@reneverheij I merged it, you can either try the master branch via or wait until next week when I release a new version of cassis on pypi via pip install git+https://github.com/dkpro/dkpro-cassis

jcklie commented 5 years ago

I released it and added documentation on how to deal with this inconvenience under https://github.com/dkpro/dkpro-cassis#miscellaneous

reckart commented 5 years ago

Might be worth introducing set_feature_value and get_feature_value methods which would automatically do this renaming internally such that the "original" feature name could be used?

jcklie commented 5 years ago

This is an extremely rare case and I do not want to add getter and setter just for this.

jcklie commented 5 years ago

Did not hear back, should be fixed.

jcklie commented 5 years ago

This is also true for type