-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to parse round-trip string objects from ruamel.yaml #36
Comments
Can you include the exception? Also, why not always use |
It's a TypeError from the pyx file:
Even though the type I'm passing through is an instance of a class that inherits from The reason not to blindly cast the input to Even my workaround is undesirable because a class that inherits from class MyStr(str):
def __str__(self):
return 'foo'
text = MyStr('hello')
assert text == 'hello'
# Undesirable, but pathological
assert str(text) == 'foo' Although that second case is fairly pathological. |
Yes, the text is defined as str (for performance reasons), and I suppose Cython doesn't accept objects that inherit from str, since it wants it the actual type to be a simple |
That's my conclusion as well, but I haven't been able to find docs that explicitly state that is the case. I'm not sure if this needs to be fixed in lark-cython or if it is better left to consumers. The workaround I'm using could be inserted either in |
Describe the bug
When parsing text from a YAML file in ruamel.YAML it it returns a
SingleQuotedScalarString
object, which does inherit from thestr
type. Sending this string to the pure-python lark parser seems to work fine, but when sending it to the cython variant it throws a TypeError.To Reproduce
The following is a MWE that reproduces the issue:
The type information it prints before it fails is:
I've tested with versions:
And
My thought is that cython would handle a class that inherits from a
str
, but perhaps it doesn't I'm not sure if this can be fixed on the lark-cython side, but I figured it was worth reporting.My current workarond is to do something like this:
The text was updated successfully, but these errors were encountered: