-
Notifications
You must be signed in to change notification settings - Fork 717
Type annotations #6278
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
base: master
Are you sure you want to change the base?
Type annotations #6278
Conversation
✅ Deploy Preview for nextflow-docs-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
d737101
to
59f9378
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.
I didn't spot any errors/typos. I've made some suggests to move the language to a active voice. Feel free to approve/reject as you see fit.
|
||
<h3>Type annotations</h3> | ||
|
||
Type annotations are a way to denote the *type* of a variable. They are useful both for documenting and validating your pipeline code. |
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.
Type annotations are a way to denote the *type* of a variable. They are useful both for documenting and validating your pipeline code. | |
You can use type annotations to denote the **type** of a variable. They help document and validate your pipeline code. |
} | ||
``` | ||
|
||
The following declarations can be annotated with types: |
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 following declarations can be annotated with types: | |
You can annotate the following declarations with types: |
|
||
Type annotations can refer to any of the {ref}`standard types <stdlib-types>`. | ||
|
||
Type annotations can be appended with `?` to denote that the value can be `null`: |
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.
Type annotations can be appended with `?` to denote that the value can be `null`: | |
You can append an `?` to type annotations to denote that the value can be `null`: |
``` | ||
|
||
:::{note} | ||
While Nextflow inherited type annotations of the form `<type> <name>` from Groovy, this syntax was deprecated in the {ref}`strict syntax <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables, but will be automatically converted to Nextflow-stype type annotations when formatting code with the language server or `nextflow lint`. |
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.
While Nextflow inherited type annotations of the form `<type> <name>` from Groovy, this syntax was deprecated in the {ref}`strict syntax <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables, but will be automatically converted to Nextflow-stype type annotations when formatting code with the language server or `nextflow lint`. | |
Nextflow previously inherited type annotations in the form `<type> <name>` from Groovy, but this syntax is now deprecated under the <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables. However, the language server and `nextflow lint` will automatically convert them to Nextflow-style type annotations when formatting code. |
def meta: Map = [:] | ||
``` | ||
|
||
While Groovy-style type annotations are still supported, the linter and language server will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version. |
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.
While Groovy-style type annotations are still supported, the linter and language server will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version. | |
Groovy-style type annotations are supported. However, the language server and `nextflow lint` will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version. |
docs/strict-syntax.md
Outdated
@@ -368,21 +380,26 @@ def map = (Map) readJson(json) // soft cast | |||
def map = readJson(json) as Map // hard cast | |||
``` | |||
|
|||
In the strict syntax, only hard casts are supported. However, hard casts are discouraged because they can cause unexpected behavior if used improperly. Groovy-style type annotations should be used instead: | |||
In the strict syntax, only hard casts are supported. |
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.
In the strict syntax, only hard casts are supported. | |
Only hard casts are supported in the strict syntax. |
docs/strict-syntax.md
Outdated
In the strict syntax, only hard casts are supported. However, hard casts are discouraged because they can cause unexpected behavior if used improperly. Groovy-style type annotations should be used instead: | ||
In the strict syntax, only hard casts are supported. | ||
|
||
When casting a value to a different type, it is always better to use an explicit method if one is available. For example, to parse a string as a 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.
When casting a value to a different type, it is always better to use an explicit method if one is available. For example, to parse a string as a number: | |
Always use an explicit method to cast a value to a different type if one is available. For example, to parse a string as a number: |
docs/strict-syntax.md
Outdated
|
||
When converting a value to a different type, it is better to use an explicit method rather than a cast. For example, to parse a string as a number: | ||
In cases where a function returns an unknown type, use a type annotation: |
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.
In cases where a function returns an unknown type, use a type annotation: | |
Use a type annotation when a function returns an unknown type: |
59f9378
to
4c520f9
Compare
Signed-off-by: Ben Sherman <[email protected]>
4c520f9
to
28157a6
Compare
This PR adds Nextflow-style type annotations for workflows, functions, and local variables.
Waiting for #5929 to be merged