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

Render union types using | #413

Closed
flying-sheep opened this issue Jan 5, 2024 · 5 comments · Fixed by #418
Closed

Render union types using | #413

flying-sheep opened this issue Jan 5, 2024 · 5 comments · Fixed by #418

Comments

@flying-sheep
Copy link
Contributor

flying-sheep commented Jan 5, 2024

Python encourages using | over Union and Optional. s-a-t should therefore render unions that way by default.

See here for more context.

Of note is the argument that Optional is actually misleading, since it implies something that doesn’t exist in Python:

  • R has true support for optional parameters via missing(param), which returns TRUE only when the function was called without specifying param.
  • Contrast with Python, where param: int | None = 4 is perfectly meaningful, while the same expressed as param: Optional[int] = 4 is very confusing: The Optional seems to relate to the fact that the parameter can be left out when calling the function, but actually means that you can specify param=None to override the default of 4. Weird!
@gboeing
Copy link

gboeing commented Jan 22, 2024

I am in total agreement with @flying-sheep. This would be a really great improvement.

@gaborbernat
Copy link
Member

I'll review a PR if someone puts one in 👍 doing the change.

@gboeing
Copy link

gboeing commented Jan 22, 2024

Thanks @gaborbernat.

@flying-sheep are you open to creating a PR for what you proposed?

@flying-sheep
Copy link
Contributor Author

I would, but #418 already exists. Also, I don‘t think it needs to be an option, it should just be how things are done, no?

@gboeing
Copy link

gboeing commented Jan 23, 2024

That was a quick PR! @flying-sheep I agree with you regarding the option... I'll leave a comment on the PR.

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 a pull request may close this issue.

3 participants