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

Fix typing errors with set_extenion methods #13613

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mribbons
Copy link

@mribbons mribbons commented Sep 2, 2024

Description

eg:

Argument of type "(span: Span, tag: str) -> str" cannot be assigned to parameter "method" of type "SpanMethod | None" in function "set_extension"
  Type "(span: Span, tag: str) -> str" is incompatible with type "SpanMethod | None"
    "function" is incompatible with protocol "SpanMethod"
      "__call__" is not present
    "function" is incompatible with "None"PylancereportArgumentType

Rationale:
Callable only accepts a single parameter, optional parameters don't work
... isn't recognized as variadic arguments (... not valid here)
SomeMethod(Protocol) __call__ approach doesn't support mapping non variadic arguments to variadic arguments.

Therefore, to not break the currently documented interface, implement a union of Callable overloads.

Types of change

Typing fix

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

eg:
```
Argument of type "(span: Span, tag: str) -> str" cannot be assigned to parameter "method" of type "SpanMethod | None" in function "set_extension"
  Type "(span: Span, tag: str) -> str" is incompatible with type "SpanMethod | None"
    "function" is incompatible with protocol "SpanMethod"
      "__call__" is not present
    "function" is incompatible with "None"PylancereportArgumentType
```

Rationale:
`Callable` only accepts a single parameter, optional parameters don't work
... isn't recognized as variadic arguments (... not valid here)
SomeMethod(Protocol) __call__ approach doesn't support mapping non variadic arguments to variadic arguments.
Therefore, to not break the currently documented interface, implement a union of Callable overloads.
@honnibal
Copy link
Member

honnibal commented Sep 9, 2024

The current way does indeed look broken, but if we can't make it correct I'd rather just declare them as Callable? The union up to an arbitrary number isn't very satisfying.

@mribbons
Copy link
Author

Hey @honnibal,

The union up to an arbitrary number isn't very satisfying.

I agree, I just didn't want to break the current API.

Turns out the docs in master use Callable anyway.

PR updated.

Copy link

@RahulVadisetty91 RahulVadisetty91 left a comment

Choose a reason for hiding this comment

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

image

First method declaration is correct, second method is incorrect.

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.

3 participants