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

text type hint in LinkButtonElement does not accept PlainTextObject/dict #1178

Closed
noqcks opened this issue Feb 17, 2022 · 2 comments · Fixed by #1183
Closed

text type hint in LinkButtonElement does not accept PlainTextObject/dict #1178

noqcks opened this issue Feb 17, 2022 · 2 comments · Fixed by #1183
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client
Milestone

Comments

@noqcks
Copy link

noqcks commented Feb 17, 2022

Reproducible in:

The following code results in a type checking error (using mypy for type checking)

 LinkButtonElement(
    text=PlainTextObject(
        text="text    
    ),
    url="http://slack.com",
)
main.py:551: error: Argument "text" to "LinkButtonElement" has incompatible type "PlainTextObject"; expected "str"

From what I understand, a PlainTextObject is appropriate for this element? https://api.slack.com/reference/block-kit/block-elements#button__examples

Could you please confirm whether 1 & 2 below are both valid
1.

 LinkButtonElement(
    text=PlainTextObject(
        text="text    
    ),
    url="http://slack.com",
)
 LinkButtonElement(
    text="text"
    url="http://slack.com",
)

The Slack SDK version

slack-sdk==3.14.1

Python runtime version

Python 3.9.6

OS info

ProductName:	macOS
ProductVersion:	12.2
BuildVersion:	21D49
Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64

Steps to reproduce:

  1. Create a LinkButtonBlock with a PlainTextObject element
  2. run mypy on your code

Expected result:

I expect to see no error from mypy

Actual result:

main.py:551: error: Argument "text" to "LinkButtonElement" has incompatible type "PlainTextObject"; expected "str"

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client and removed untriaged labels Feb 17, 2022
@seratch
Copy link
Member

seratch commented Feb 17, 2022

Hi @noqcks, thanks for taking the time to report this!

You are right that both should be accepted. Specifically, the type hint here should be Union[str, dict, PlainTextObject] and the internals of the constructor should work with any of the types.

We will improve this in the next release.

@seratch seratch added this to the 3.16.0 milestone Feb 17, 2022
@seratch seratch changed the title LinkButtonElement is incorrectly typed text in LinkButtonElement does not accept PlainTextObject/dict Feb 17, 2022
@seratch seratch changed the title text in LinkButtonElement does not accept PlainTextObject/dict text type hint in LinkButtonElement does not accept PlainTextObject/dict Feb 18, 2022
seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 18, 2022
seratch added a commit that referenced this issue Feb 18, 2022
@seratch
Copy link
Member

seratch commented Feb 18, 2022

Thanks again for reporting this issue! We are going to release a new patch version fixing this issue soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client
Projects
None yet
2 participants