-
Notifications
You must be signed in to change notification settings - Fork 326
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
Tidy Standard.Base part 5 of n ... (hopefully the end...) #3929
Conversation
46aac45
to
8f3dbd7
Compare
14b25ed
to
8a707de
Compare
- Standard.Base.Network.Http.put_json | ||
- Standard.Base.Network.Http.head | ||
- Standard.Base.Network.Http.options | ||
- Standard.Base.Network.HTTP.HTTP.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the component groups visible in component browsers! Yeah, simplifying the Web
part is probably good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A start at tidying Web API. Will design and expand over next month or two.
> Example | ||
Convert a vector to JSON. | ||
[1, 2, 3, 4].to_json | ||
Any.to_json : Json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving these extension methods from Json.enso
to Json/Extensions.enso
helps with with imports somehow, right? How the imports looked and will look once this PR is integrated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from Standard.Base import alll
brings it in, and will be the general way for users.
Within Standard.Base
or being explicit import Standard.Base.Data.Json.Extensions
adds the to_json
support in.
I imagine we will replace to_json
with a Json.from
method and use to Json
. With the exception of Text we have less and less extension methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like that we are getting a more explicit way to import the extension methods (by importing this separate module). It feels a lot cleaner (although I appreciate auto-importing them in the from Standard.Base import all
also makes sense).
@@ -19,7 +19,7 @@ polyglot java import org.enso.base.ObjectComparator | |||
Otherwise can support a custom fallback comparator. | |||
new : Nothing | (Any -> Any -> Ordering) -> ObjectComparator | |||
new custom_comparator=Nothing = | |||
comparator_to_java cmp x y = handle_incomparable_value (cmp x y . to_sign) | |||
comparator_to_java cmp x y = Incomparable_Values_Error.handle_errors (cmp x y . to_sign) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to point out that various compare_to
methods throw different Error
. Shouldn't all compare failures result into the same Incomparable_Values_Error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that would be a fair step but out of scope for this PR.
65c3a47
to
663e302
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -310,9 +312,9 @@ into_helper fmt json = case fmt of | |||
_ -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This into_helper
may need to be revisited in some future - I think the way it (ab)uses the atoms to create the formats will be violating our up-coming type system.
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso
Outdated
Show resolved
Hide resolved
# TODO Dubious constructor export | ||
from project.Data.Text.Matching.No_Matches_Found import all | ||
from project.Data.Text.Matching.No_Matches_Found export all | ||
from project.Data.Boolean import Boolean, True, False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes me think if we should have a Standard.Core
covering the most primitive types, essentially replacing the micro-distribution
.
Then in proper Standard.Base
we could do from Standard.Core import all
instead. And ofc we'd re-export Core
in Base
, so that regular users would just use Base
.
distribution/lib/Standard/Base/0.0.0-dev/src/Network/Extensions.enso
Outdated
Show resolved
Hide resolved
…o Json extensions.
Tidy Regex_Mode.
scheme : Text ! Nothing | ||
scheme self = Internal.handle_nothing self.internal_uri.getScheme | ||
scheme self = handle_nothing self.internal_uri.getScheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not be for this PR, but IMO this API needs to be revisited.
I highly doubt what we want to do here is to throw Nothing
. Apart from some control flow, I doubt we want to throw Nothing
ever - once it is caught somewhere down the dataflow, it's impossible to tell what it originated from or what it means. It's also rather unclear for the user to see 'Nothing' was thrown. If it was a convention we used across all stdlib and users were used to it (it kind of used to be) then maybe it would be ok, but in just a few places, it is a source of confusion IMO.
IMO we should either throw some more meaningful error like Missing_Field
or something. But ideally, I'd just return Nothing
as a value instead, making the type not Text ! Nothing
but Text | Nothing
.
What do you think @jdunkerley ?
Also, I'm not saying to adapt it in this PR (let's merge it ASAP), but I think may be worth noting so that we revisit it in the near future.
## PRIVATE | ||
|
||
Utility method for running an action with Java exceptions mapping. | ||
handle_java_exceptions file ~action = | ||
Panic.catch IOException action caught_panic-> | ||
File_Error.wrap_io_exception file caught_panic.payload.cause | ||
|
||
## PRIVATE | ||
|
||
Converts a Java `IOException` into its Enso counterpart. | ||
wrap_io_exception file io_exception = | ||
if io_exception.is_a NoSuchFileException then Error.throw (File_Error.Not_Found file) else | ||
if io_exception.is_a FileAlreadyExistsException then Error.throw (File_Error.Already_Exists file) else | ||
if io_exception.is_a AccessDeniedException then Error.throw (File_Error.IO_Error file "You do not have permission to access the file") else | ||
Error.throw (File_Error.IO_Error file "An IO error has occurred: "+io_exception.to_text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all that logic, this file is growing pretty fast. It's already quite large.
Maybe we should not keep all basic errors in a single file. What about sorting them into smaller modules 'thematically' and then possibly re-exporting through Common
for easier importing?
I think it would be more manageable, as such big files are a bit of a pain.
> Example | ||
Convert a success code to a corresponding number. | ||
|
||
import Standard.Base.System.Process.Exit_Code | ||
import Standard.Base.System.Process.Exit_Code.Exit_Code | ||
|
||
example_to_number = Exit_Code.Exit_Success.to_number | ||
example_to_number = Exit_Code.Success.to_number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes me remember that we used to have plans to have an automatic compilation of Examples.
I think it is something worth considering soon-ish so that we can assure that the examples provided in the docs are correct.
IMO likely this may not take much more time than manually making sure all of them work - and before an official release we definitely should make sure the examples are correct - giving incorrect examples to the users is going to be extremely annoying for them. And given so many refactors I'm almost sure there are other examples which are broken, however careful we would be it's hard to keep track of all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree need to validate examples - yes picking them out and building them automagically seems right to me.
@@ -106,7 +106,7 @@ type Warning | |||
> Example | |||
Detach warnings of a specific type. | |||
|
|||
result = Warning.detach_selected_warnings value (_.is_a Illegal_State_Error) | |||
result = Warning.detach_selected_warnings value (_.is_a Illegal_State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = Warning.detach_selected_warnings value (_.is_a Illegal_State) | |
result = Warning.detach_selected_warnings value (_.is_a Illegal_State.Error) |
While I'd expect is_a
to work the way you expect too, I don't think that is the case currently.
I run an example check:
from Standard.Base import all
type Foo
Bar x
main =
y = Foo.Bar 42
IO.println <| y.is_a Foo
IO.println <| y.is_a Foo.Bar
and it gives back
False
True
We'd probably both expect both to be True
, but currently that is not the case.
I think we need to revisit how is_a
works, along with how Panic.catch
, Error.catch
and Panic.recover
filtering also works.
cc: @hubertp @JaroslavTulach as I'm not sure who would be scheduling the fixes to these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was broken before Illegal_State_Error
is the type as well. I agree we should review is_a
and catch
.
Ideally would be able to pass both as you say.
distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Postgres/Postgres_Connection.enso
Outdated
Show resolved
Hide resolved
@@ -52,5 +52,5 @@ number_input = Error.unimplemented "This function should not be called." | |||
column_1 = ["name", "Enso"] | |||
column_2 = ["stars", 5000] | |||
table = Table.new [column_1, column_2] | |||
table_input = Error.unimplemented "This function should not be called." | |||
table_input = Unimplemented.throw "This function should not be called." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only now noticed it. I understand that it is supposed to allow easy access to the examples.
But will the component browser somehow know to not insert these fake functions into nodes? I guess it will just insert them. Won't this be weird and confusing?
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Visualization/0.0.0-dev/src/Helpers.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Visualization/0.0.0-dev/src/SQL/Visualization.enso
Outdated
Show resolved
Hide resolved
# TODO Dubious constructor export | ||
from project.Data.Text.Regex.Engine.Default.Option import all | ||
from project.Data.Text.Regex.Engine.Default.Option export all | ||
|
||
## Options specific to the `Default` regular expression engine. | ||
type Option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think maybe it would be worth re-exporting the global Regex_Options
in this Option
type? So that we could mark that all options - both engine specific and global can be accessed through it?
(not sure though as it may cause confusion that the global ones are of different type, so there are pros and cons to this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Regex design is not the final one - we are going to redo it in due course.
Hopefully the lower level engine will never be exposed to end users!
test/micro-distribution/lib/Standard/Base/0.0.0-dev/src/Error.enso
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
d49b224
to
5308982
Compare
Pull Request Description
Any
,Error
andPanic
toStandard.Base
.Json
andRange
extensions into own modules.Case
,Case_Sensitivity
,Encoding
,Matching
,Regex_Matcher
,Span
,Text_Matcher
,Text_Ordering
andText_Sub_Range
inStandard.Base.Data.Text
.Standard.Base.Data.Text.Extensions
and stopped it re-exporting anything.Regex_Mode
. RenamedOption
toRegex_Option
and added type to export.Regex
space.Meta
space.Matching
from export.Standard.Base.Data.Boolean
toStandard.Base.Boolean
.Additional Work
Standard.Table
dependency onStandard.Visualization
by movingdefault_visualization
to be an extension method.Standard.Database
.Standard.Database
in line with design in ticket.Important Notes
to_json
andto_default_visualization_data
from base types to extension methods.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.