-
Notifications
You must be signed in to change notification settings - Fork 27
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
Type names and union tags can't have the same name in Python target #68
Comments
There is a several options: Just restrict to use same name for type and union tag at the schema level.
For Python target, compile union tags to be the inner class of its union type like:
|
@Kroisse I personally prefer the latter, but I think it can be mixed some pros of both. For example, if there aren't types of the same name, we can make a module-level alias for tags e.g. @admire93 Thoughts? |
@dahlia It could be hard to expect. Because both of union tag and record are compiled to the Python class, they can be mixed in the user's code easliy, and lead to a bug which is hard to discover what is wrong. The user also can make an alias, so I think it's better to let them do. We don't need to give a bad default. |
So you're suggesting ways like using annotation, right? |
I'm prefer to provide an alias module, e.g.
Still nasty, though. |
@Kroisse Unless I misunderstood it you are suggesting making a Python module named after the union name. For example, if there are
|
I prefer the latter also. however i don't have a strong opinion about aliasing. |
And we need to discuss about the case that is the the origin of this issue. With this discussion, we can solve only the namespace conflict between union tags and other types. But some problem is still remained when I want to define several records and use them directly as a union:
Serialization is also problematic:
updated: fixed "_type" to "_tag" |
@dahlia: That's right, and I understand that can be lead a circular import. |
In the case of
|
Instead of making an alias module (which may introduce another name conflicts), how about making Python target to provide aliasing option through annotation? E.g.:
|
Since Nirum 0.4 the compile will become to disallow to use the same name for a type name and a union tag name (or an enum member name). See also PR #254. |
In Python target, because union tags are compiled to subtypes, if there's a name shared between a type and a union tag, one of them is overridden by other one. There can be also similar situation when there are tags of the same name but belonging to other unions.
Reported by @yjroot.
The text was updated successfully, but these errors were encountered: