-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Document reservation of double underscore names (dunders) #51215
base: master
Are you sure you want to change the base?
Conversation
Just for future reference, this is talking about this proposal: |
Should they be? |
Co-authored-by: 3f6a <126961207+3f6a@users.noreply.github.com>
@c42f would there be a way to enforce this via JuliaSyntax.jl? |
fwiw I don't think lack of enforcement should hold up this PR, since documenting existing expectations is a definite improvement over not documenting them, and the text could easily be updated in a future PR if some enforcement is added |
One could forbid new names with |
I think the enforcement matter should be opened as a new issue once this is merged. |
Maybe I'm missing something, but this syntax still doesn't have a consistent functionality or semantic meaning. The most consistent thing I've seen is that it is expands to a new value informed by the context of a macro call. But Is the intent here just to guarantee that |
Yes. See for instance discussion at #50974. |
I've read through that. Keno pointed out that it doesn't have any unique meaning in Julia. If there's a plan to use this for something that makes sense. However, there currently isn't any technical reason users shouldn't use this syntax and there doesn't appear to be any consensus how this should be uniformly unique in the future. If we aren't going to change how this syntax is parsed this is escalating stylistic convention to formal API. |
@StefanKarpinski asserted that "__ names are reserved" here: However, we noticed that this is not documented anywhere. Independent of if we use |
But why are they reserved? |
They are reserved to provide a namespace for the Julia Language in case we need it to expand for matters that we cannot currently anticipate. Python has a fair number of these at the moment, many of which Julia does not need. https://docs.python.org/3/reference/lexical_analysis.html?highlight=dunder There, they issue this warning:
It seems we have also started to follow this convention without clearly stating it. |
Apparently ISO C and C++ also make some reservations for identifiers with double underscores.
https://en.wikipedia.org/wiki/Naming_convention_%28programming%29?wprov=sfla1 |
I'm not arguing that we need to have everything figured out right now.
I actually think it would be really cool to have something that provides better contextual parsing outside of macros. But we already have an issue with properly documenting and enforcing public/private APIs. I think it would make more sense to first ensure this could even be implemented prior to Julia 2.0 |
First, let me emphasize a very important aspect of this. I'm not changing public API. I'm merely documenting part of the API that was not previously stated clearly. While it might not be stated explicitly, it could be inferred from currently documented identifiers and the tradition of languages proceeding Julia that double underscore identifiers were reserved. Languages do not come from a vacuum but rather draw prior art. I can understand the perspective that this can not be public API since it was not documented. It is because of this perspective that I propose this pull request with some urgency.
As for existing identifiers using that use the reserved pattern, there is a fair case that these should be grandfathered in. Additionally, I note that Revise.jl and ReTest.jl may have special license to act on behalf of the language. |
Friendly bump. Not sure if a conclusion was reached here? |
Late to the discussion here sorry... but FWIW I don't think we should involve the parser here - the Juila parser allows many constructs which aren't valid Julia code, but may be consumed by macros and turned into something valid. I think the "correct" place to emit a warning (or error, or whatever is decided) would be in lowering. |
Just to be sure, is this just a double, or at least a double? This may be a silly question, but given that several packages use their dunders, I don't think it's a bad idea to warrant their substitutions. |
I would go with the following operational definition. julia> function isreserved(name)
name = string(name)
return startswith(name, "__") && endswith(name, "__")
end
isreserved (generic function with 1 method)
julia> isreserved(:___is_a_triple_reserved___)
true Triple underscores could be delegated later after establishing this convention. |
This comment was marked as resolved.
This comment was marked as resolved.
Do we mention anything about |
This comment was marked as resolved.
This comment was marked as resolved.
I am unclear what the ambiguity is then.
Please make a specific suggestion to improve the pull request. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I simply do not understand the issue you are raising and thus cannot fix it. I'm not sure if we are still talking about |
In the recent discussion about
main
,__main__
was proposed. One reason in favor of this is that double underscore, or dunder, names are reserved names in Julia. This however is not documented.This pull request adds a paragraph reserving double underscore names for Julia.
They are added to Base -> Essentials -> Keywords where other reserved names are documented.
https://docs.julialang.org/en/v1.11-dev/base/base/#Keywords
cc: @StefanKarpinski