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

API behavior is surprising with respect to Python types #131

Closed reckart closed 4 years ago

reckart commented 4 years ago

Describe the bug Not actually a bug, but the behaviour of the API is a bit surprising...

To Reproduce

typesystem = TypeSystem()

ExampleType = typesystem.create_type(name='example.Type')
typesystem.add_feature(type_=ExampleType, name='self', rangeTypeName='String')
typesystem.add_feature(type_=ExampleType, name='type', rangeTypeName='String')

annotation = ExampleType(self_="Test string1", type_="Test string2")

# Prints "Type" instead of whatever a Python class should print as
print(type(ExampleType).__name__)

# Prints "example_Type" instead of "ExampleType" (plus module)
print(type(annotation).__name__)

# Crashes because ExampleType is not actually a class
print(isinstance(annotation, ExampleType))

Expected behavior

isinstance(annotation, ExampleType) == true
jcklie commented 4 years ago
print(isinstance(annotation, ExampleType._constructor))

Works. ExampleType is a factory, not the class of annotation.

jcklie commented 4 years ago

Not a bug and nothing we can do about except a complete rewrite.