rich icon indicating copy to clipboard operation
rich copied to clipboard

🐛 Fix type annotations for `@group` decorator

Open tiangolo opened this issue 3 years ago • 1 comments

Type of changes

  • [x] Bug fix
  • [ ] New feature
  • [ ] Documentation / docstrings
  • [ ] Tests
  • [x] Other (type annotations)

Checklist

  • [ ] I've run the latest black with default args on new code.
  • [ ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • [ ] I've added tests for new code.
  • [x] I accept that @willmcgugan may be pedantic in the code review.

Description

The current type annotations for rich.console.group discard any type information in the original function.

This means that calling the function decorated with @group() doesn't get autocompletion nor inline errors for the arguments.

This is how it looks right now, notice that it should be showing an error:

Selection_167

And there's no autocompletion for the function parameters:

Selection_168

This change fixes the type annotations of the resulting function decorated with @group().

Now it shows errors:

Selection_169

And it shows autocompletion:

Selection_170

tiangolo avatar Jul 09 '22 01:07 tiangolo

Hehe, it seems there's a discrepancy in the types, not sure. I suspect the new types caught something not completely right. It probably needs an update in the types for group() or in the types for traceback._render_syntax_error(), but I'm not sure which one of the two is wrong...

tiangolo avatar Jul 09 '22 01:07 tiangolo

Thanks. I think we might tackle this as part of a larger review of typing. https://github.com/Textualize/rich/issues/2846

willmcgugan avatar Mar 04 '23 11:03 willmcgugan