Skip to content
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

Add namereplace error handler #1140

Merged
merged 3 commits into from
Mar 19, 2021
Merged

Conversation

slozier
Copy link
Contributor

@slozier slozier commented Mar 18, 2021

Resolves #1114

@slozier slozier requested a review from BCSharp March 18, 2021 16:20
@BCSharp
Copy link
Member

BCSharp commented Mar 18, 2021

Today I am AFK, but can look at it tomorrow.

@@ -2638,6 +2644,69 @@ private class ExceptionFallbackBufferUtf8DotNet : ExceptionFallbackBuffer {
}
}

private static object NameReplaceErrors(object unicodeError) {
Modules.unicodedata.PerformModuleReload(null, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar call in LiteralParser, which has been bothering me already for some time, since I had thought of enabling nullable annotations in unicodedata.cs. The old-style nullable annotations in the definition of unicodedata.PerformModuleReload mark both parameters as not-null. And indeed, PythonContext seems to be expected to be not null everywhere in the code base. It appears that in both and only cases of the explicit call to PythonModuleReload the goal is simply to make sure the private static variable ucd_5_2_0 is properly initialized. So perhaps factor that out of PythonModuleReload into a parameterless internal method? I don't know what the [SpecialName] PerformModuleReload is supposed to represent in the general case to decide whether it is OK for the parameters to become nullable or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with making an internal method to initialize ucd_5_2_0. Presumably the analyzer should handle [SpecialName] PerformModuleReload in a PythonModule and check that the arguments are non-null (and don't have [NotNull] since it's not Python callable).

While on the subject of NotNull I've also been thinking about the conflict with the standard nullable annotation attribute. I wonder if we should create a new attribute to avoid the conflict. Unfortunately I can't come up with a good name for this new attribute. Perhaps DlrNotNull, although it's likely to prevent any future collisions it's not super descriptive.

Something to keep in mind for the future, if that if we want to mimic CPython, whenever we use the namereplace error handler or \N in a string we should load the unicodedata module in sys.modules. So something more along the lines of what we do with PythonContext.EnsureEncodings (although it's slightly different since unicodedata is embedded in our main library instead of being an external module).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While on the subject of NotNull I've also been thinking about the conflict with the standard nullable annotation attribute. I wonder if we should create a new attribute to avoid the conflict. Unfortunately I can't come up with a good name for this new attribute. Perhaps DlrNotNull, although it's likely to prevent any future collisions it's not super descriptive.

I was wondering the same. Some time ago I have made a suggestion naming it NotNone but it is Python-centric... DLR itself calls a null type DynamicNull, but [NotDynamicNull] looks too long... NotDNull?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotDNull seems a bit obscure. I think I could live with NotDynamicNull...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I could live with that too...

@BCSharp
Copy link
Member

BCSharp commented Mar 19, 2021

Looks good to me, except for a small comment.

@slozier slozier merged commit ef9a15e into IronLanguages:master Mar 19, 2021
@slozier slozier deleted the namereplace branch March 19, 2021 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add namereplace error handler on encode
2 participants