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

Type hint error for enum shared link access #385

Closed
3 of 4 tasks
supermitch opened this issue Nov 20, 2024 · 1 comment
Closed
3 of 4 tasks

Type hint error for enum shared link access #385

supermitch opened this issue Nov 20, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@supermitch
Copy link

supermitch commented Nov 20, 2024

Description of the Issue

Your docs show this example:

client.shared_links_folders.add_share_link_to_folder(
    folder.id,
    "shared_link",
    shared_link=AddShareLinkToFolderSharedLink(
        access=AddShareLinkToFolderSharedLinkAccessField.OPEN.value,
        password="Secret123@",
    ),
)

Note the ...OPEN.value. This is causing a type hint issue, because the literal string 'open' does not match your definition for access argument:

class AddShareLinkToFolderSharedLink(BaseObject):
    def __init__(
        self,
        *,
        access: Optional[AddShareLinkToFolderSharedLinkAccessField] = None,

It is expecting AddShareLinkToFolderSharedLinkAccessField only, e.g. .OPEN

Shouldn't the type hint be access: Optional[str] = None?

ps: Your box Developer Forum link is broken, above.

Steps to Reproduce

Edit your example code in IDE.

Expected Behavior

I think this is a frustrating issue with Python enum type hinting, per https://stackoverflow.com/a/67292548/515368 this answer.

I think you have to type hint with Literal[Enum.value1, Enum.Value2, ...] to fix this, or simply accept type of str (my preferred solution).

Error Message, Including Stack Trace

No errors, just type hinting.

Screenshots

image

Versions Used

Python SDK: box-sdk-gen 1.3.0
Python: 3.10.12

@mwwoda
Copy link
Contributor

mwwoda commented Nov 21, 2024

Hi,
Thanks for reporting the issue. Looks like it's specific to some of the language servers (like pylance in this case)

Should be fixed by #387

Correct usage of your example shown here https://github.com/box/box-python-sdk-gen/pull/387/files#diff-54de40207be913e76b6a9669129cc318c802c1fdbd0f5ec5c3b055642cc4ac72 (no .value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants