Skip to content

Conversation

@bentsherman
Copy link
Member

Looking at the standard library functions with an eye towards static type checking, the only problematic function is file() which can return a single file or list of files based on the glob pattern.

Rather than introduce some new function, I think we can transition file() to be properly typed:

  1. for now, warn if file() matches a collection of files
  2. in the future, change the return type of file() to Path and raise an error if the glob pattern matches zero or multiple files

Note that the glob pattern is still useful for file() when you know it will match only one file but you don't want to spell it out. Raising an error when this assumption is wrong seems like the right approach to me, but of course we should keep it as a warning just for now.

Not sure whether you want to add a test for the warning, but you can see it in action here:

// assumes there are no *.foo files in the launch directory
println file('*.foo')
println file('*.nf')
println files('*.foo')
println files('*.nf')

@bentsherman bentsherman requested a review from a team as a code owner November 14, 2024 15:46
@netlify
Copy link

netlify bot commented Nov 14, 2024

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit da0f861
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/68a8633aa74a280008210017
😎 Deploy Preview https://deploy-preview-5507--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bentsherman bentsherman added this to the 25.04.0 milestone Nov 14, 2024
@christopher-hakkaart
Copy link
Collaborator

Is it appropriate to document files() should be used only for a collection of files at the same time?

@bentsherman
Copy link
Member Author

Agreed, better to describe files() on its own terms

@christopher-hakkaart
Copy link
Collaborator

I've added a minor suggestion. Otherwise, the docs look good.

@bentsherman bentsherman requested review from pditommaso and removed request for pditommaso March 17, 2025 15:28
@christopher-hakkaart
Copy link
Collaborator

Docs look good to me 👍

@bentsherman
Copy link
Member Author

Since the change from file() to files() is pretty simple, and runtime warnings tend to adversely affect non-developer users, I think we can do without this warning and simply add a type-checking error whenever the developer opts into static type checking in the future

@bentsherman bentsherman closed this May 8, 2025
@bentsherman bentsherman changed the title Warn when file() matches a collection of files Warn when file() matches a collection of files Aug 8, 2025
@bentsherman bentsherman reopened this Aug 8, 2025
@bentsherman bentsherman added this to the 25.10 milestone Aug 8, 2025
@bentsherman
Copy link
Member Author

Reviving this PR.

We removed several runtime warnings since they were more appropriate in the linter / language server. However, after reflecting on it more, I think this one needs to be a runtime warning, since the glob pattern is only evaluated at runtime.

I kept it as a warning and enabled only in the strict syntax, so it shouldn't be too bothersome.

Copy link
Collaborator

@christopher-hakkaart christopher-hakkaart left a comment

Choose a reason for hiding this comment

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

Added a couple of suggestion. Feel free to accept or reject.

Co-authored-by: Chris Hakkaart <[email protected]>
Signed-off-by: Ben Sherman <[email protected]>
Copy link
Collaborator

@christopher-hakkaart christopher-hakkaart left a comment

Choose a reason for hiding this comment

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

Docs look good 👍

@bentsherman bentsherman merged commit 726bf48 into master Aug 22, 2025
22 of 23 checks passed
@bentsherman bentsherman deleted the warn-file-function branch August 22, 2025 13:01
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.

4 participants