python lsp
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import cattrs
|
||||
|
||||
from . import _hooks
|
||||
|
||||
|
||||
def get_converter(
|
||||
converter: Optional[cattrs.Converter] = None,
|
||||
) -> cattrs.Converter:
|
||||
"""Adds cattrs hooks for LSP lsp_types to the given converter."""
|
||||
if converter is None:
|
||||
converter = cattrs.Converter()
|
||||
return _hooks.register_hooks(converter)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import attrs
|
||||
|
||||
INTEGER_MIN_VALUE = -(2**31)
|
||||
INTEGER_MAX_VALUE = 2**31 - 1
|
||||
|
||||
|
||||
def integer_validator(
|
||||
instance: Any,
|
||||
attribute: "attrs.Attribute[int]",
|
||||
value: Any,
|
||||
) -> bool:
|
||||
"""Validates that integer value belongs in the range expected by LSP."""
|
||||
if not isinstance(value, int) or not (
|
||||
INTEGER_MIN_VALUE <= value <= INTEGER_MAX_VALUE
|
||||
):
|
||||
name = attribute.name if hasattr(attribute, "name") else str(attribute)
|
||||
raise ValueError(
|
||||
f"{instance.__class__.__qualname__}.{name} should be in range [{INTEGER_MIN_VALUE}:{INTEGER_MAX_VALUE}], but was {value}."
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
UINTEGER_MIN_VALUE = 0
|
||||
UINTEGER_MAX_VALUE = 2**31 - 1
|
||||
|
||||
|
||||
def uinteger_validator(
|
||||
instance: Any,
|
||||
attribute: "attrs.Attribute[int]",
|
||||
value: Any,
|
||||
) -> bool:
|
||||
"""Validates that unsigned integer value belongs in the range expected by LSP."""
|
||||
if not isinstance(value, int) or not (
|
||||
UINTEGER_MIN_VALUE <= value <= UINTEGER_MAX_VALUE
|
||||
):
|
||||
name = attribute.name if hasattr(attribute, "name") else str(attribute)
|
||||
raise ValueError(
|
||||
f"{instance.__class__.__qualname__}.{name} should be in range [{UINTEGER_MIN_VALUE}:{UINTEGER_MAX_VALUE}], but was {value}."
|
||||
)
|
||||
return True
|
||||
Reference in New Issue
Block a user