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

Support type annotations #203

Open
davidbrochart opened this issue Dec 11, 2024 · 0 comments · May be fixed by #204
Open

Support type annotations #203

davidbrochart opened this issue Dec 11, 2024 · 0 comments · May be fixed by #204
Labels
enhancement New feature or request

Comments

@davidbrochart
Copy link
Collaborator

davidbrochart commented Dec 11, 2024

Problem

Currently, a Doc or a shared type (Map, Array...) don't allow type annotations. This prevents catching errors at static analysis, or editor completion support.

Proposed Solution

Support type annotations on Doc and shared types. For instance:

from pycrdt import Array, Doc, Map

doc = Doc()
map0: Map[bool] = doc.get("map0", type=Map)
array0: Array[int] = doc.get("array0", type=Array)

map0["foo"] = "bar"  # error: Incompatible types in assignment (expression has type "str", target has type "bool")  [assignment]
array0.append("baz")  # error: Argument 1 to "append" of "Array" has incompatible type "str"; expected "int"  [arg-type]

Additional context

Some support for dynamic document validation was introduced in #38 (see also #65), but this issue is bout static typing.

@davidbrochart davidbrochart added the enhancement New feature or request label Dec 11, 2024
@davidbrochart davidbrochart linked a pull request Dec 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant