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

Refactoring: TypedDict has been added to the typing module #964

Closed
newwingbird opened this issue Oct 12, 2024 · 1 comment
Closed

Refactoring: TypedDict has been added to the typing module #964

newwingbird opened this issue Oct 12, 2024 · 1 comment

Comments

@newwingbird
Copy link
Contributor

newwingbird commented Oct 12, 2024

Chore

Refactoring

In Python 3.8 and later, TypedDict has been added to the typing module.

from typing_extensions import NotRequired, TypedDict
class RealtimeClientOptions(TypedDict, total=False):
auto_reconnect: NotRequired[bool]
hb_interval: NotRequired[int]
max_retries: NotRequired[int]
initial_backoff: NotRequired[float]

The README says Install the package (for Python > 3.7):, but I think it actually supports Python >= 3.9.

Install the package (for Python > 3.7):

python-version: ["3.9", "3.10", "3.11", "3.12"]

Proposal

It can be refactored as follows

from typing import TypedDict

class RealtimeClientOptions(TypedDict, total=False):
    auto_reconnect: bool
    hb_interval: int
    max_retries: int
    initial_backoff: float

Here, instead of specifying each field as NotRequired, all fields are treated as optional with total=False. This makes the code simpler and more readable. reference

If it's convenient for you, I would be happy to help you.

@silentworks
Copy link
Contributor

Ah good catch. Also thanks for the PR, I will review it soon.

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

No branches or pull requests

2 participants