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

Investigate strong typing for REST API payloads and responses #89

Closed
t1m0thyj opened this issue Jun 17, 2022 · 2 comments · Fixed by #322
Closed

Investigate strong typing for REST API payloads and responses #89

t1m0thyj opened this issue Jun 17, 2022 · 2 comments · Fixed by #322
Assignees
Labels
enhancement New feature or request priority-medium
Milestone

Comments

@t1m0thyj
Copy link
Member

t1m0thyj commented Jun 17, 2022

Perhaps we can use some new Python features like type hints (in 3.5) and dataclasses (in 3.7).

Some examples of where this would be nice:

  • The options dictionary for create_data_set in the zos-files SDK
  • The response object returned by submit_job in the zos-jobs SDK
@zFernand0 zFernand0 added enhancement New feature or request priority-low labels Mar 9, 2023
@deadaf
Copy link
Contributor

deadaf commented May 20, 2023

Hello @t1m0thyj

This would certainly improve the codebase's readability and working with the packages easier. I'm interested in working on this and adding type hints wherever applicable.

Before I proceed, I wanted to check if there are any specific guidelines or conventions for adding type hints in the project. Additionally, I would appreciate any guidance or considerations you might have regarding the use of type hints and dataclasses.

Please let me know your thoughts on this, and if there's anything specific I should keep in mind while working on this issue. Thank you!

@t1m0thyj t1m0thyj moved this to Low Priority in Zowe CLI Squad Dec 26, 2023
@zFernand0 zFernand0 added this to the v1 LTS milestone Jun 11, 2024
@zowe-robot zowe-robot moved this from Low Priority to Medium Priority in Zowe CLI Squad Jul 12, 2024
@t1m0thyj
Copy link
Member Author

For return types, we want simple dataclasses that support both dot notation (e.g. obj.property) and bracket notation (e.g. obj["property"]) to combine the features of namespaces and dictionaries with type hints.

Here is an example from ChatGPT:

from dataclasses import dataclass, field
from typing import Any


@dataclass
class ExtendedDataClass:
    attribute1: str = field(default="")
    attribute2: int = field(default=0)

    def __getitem__(self, key: str) -> Any:
        return self.__dict__[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.__dict__[key] = value


# Example usage
obj = ExtendedDataClass(attribute1="value1", attribute2=42)

# Accessing attributes
print(obj.attribute1)  # Using dot notation
print(obj["attribute1"])  # Using bracket notation

# Setting attributes
obj.attribute1 = "new_value1"  # Using dot notation
obj["attribute2"] = 84  # Using bracket notation

print(obj.attribute1)
print(obj.attribute2)

@pem70 pem70 mentioned this issue Aug 7, 2024
4 tasks
@t1m0thyj t1m0thyj linked a pull request Aug 13, 2024 that will close this issue
4 tasks
@github-project-automation github-project-automation bot moved this from Medium Priority to Closed in Zowe CLI Squad Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority-medium
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

4 participants