Skip to content

Union types #315

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

Draft
wants to merge 3 commits into
base: starlark-with-types
Choose a base branch
from
Draft

Conversation

comius
Copy link
Contributor

@comius comius commented May 16, 2025

No description provided.

comius added 3 commits May 16, 2025 12:46
This is a top type. Previously it was omitted in the design, but it is needed to correctly type methods in the builtin method library.
### Unions

Some functions may accept parameters of multiple types. In this
case parameter is annotated with a union type `A|B`.
Copy link
Member

Choose a reason for hiding this comment

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

nit: the parameter

Some functions may accept parameters of multiple types. In this
case parameter is annotated with a union type `A|B`.

User functions are limited to optional types, that is `None|A`,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "user functions" might be ambiguous between application-defined vs starlark-programmer-defined. Maybe "Starlark-defined functions"? Not sure whether there's precedent terminology elsewhere in this spec.

@@ -3333,6 +3350,8 @@ See https://github.com/bazelbuild/starlark/issues/47.

### float

`float(x: str|bool|int|float, /) -> float`
Copy link
Member

Choose a reason for hiding this comment

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

(No action needed for this PR) There may be a bunch of other args to other builtins that are Noneable, in the sense that we take None as an alternative to omitting the parameter entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants