Skip to content

Commit

Permalink
Fixup name collision
Browse files Browse the repository at this point in the history
  • Loading branch information
elchupanebrej committed Dec 8, 2024
1 parent 98588f3 commit 2b02397
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 3 additions & 0 deletions python/src/cucumber_messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from . import json_converter
from .messages import *

PickleStepType = Type
ExpressionType = Type1

del Type
del Type1
15 changes: 7 additions & 8 deletions python/src/cucumber_messages/json_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from dataclasses import fields, is_dataclass, Field, MISSING
from datetime import datetime, date
from enum import Enum
from typing import Any, Dict, List, Optional, Union, get_args, get_origin, TypeVar, Type, Tuple
from typing import Any, Dict, List, Optional, Union, get_args, get_origin, TypeVar, Type as TypingType, Tuple

T = TypeVar('T')


def camel_to_snake(name: str) -> str:
"""Convert string from camelCase to snake_case."""
# Validate field name - must start with letter or underscore and contain only alphanumeric and underscore
Expand Down Expand Up @@ -40,7 +39,7 @@ def __init__(self, module_scope: types.ModuleType):
self.module_scope = module_scope
self.type_cache = {}

def resolve_container_type(self, container_name: str) -> Type:
def resolve_container_type(self, container_name: str) -> TypingType:
container_types = {
'Sequence': typing.Sequence,
'List': list,
Expand All @@ -52,7 +51,7 @@ def resolve_container_type(self, container_name: str) -> Type:
raise ValueError(f"Unsupported container type: {container_name}")
return container_types[container_name]

def parse_generic_type(self, type_str: str) -> Tuple[Type, List[Type]]:
def parse_generic_type(self, type_str: str) -> Tuple[TypingType, List[TypingType]]:
container_name = type_str[:type_str.index('[')].strip()
args_str = type_str[type_str.index('[') + 1:type_str.rindex(']')]

Expand All @@ -65,7 +64,7 @@ def parse_generic_type(self, type_str: str) -> Tuple[Type, List[Type]]:

return container_type, arg_types

def resolve_type(self, type_str: str) -> Type:
def resolve_type(self, type_str: str) -> TypingType:
if type_str in self.type_cache:
return self.type_cache[type_str]

Expand All @@ -84,7 +83,7 @@ def resolve_type(self, type_str: str) -> Type:
self.type_cache[type_str] = resolved
return resolved

def _resolve_union_type(self, type_str: str) -> Type:
def _resolve_union_type(self, type_str: str) -> TypingType:
types_str = [t.strip() for t in type_str.split('|')]
resolved_types = [
self.resolve_type(t)
Expand Down Expand Up @@ -293,11 +292,11 @@ def to_dict(self) -> Dict[str, Any]:
return DataclassJSONEncoder.encode(self)

@classmethod
def from_json(cls: Type[T], json_str: str, module_scope: Optional[types.ModuleType] = None) -> T:
def from_json(cls: TypingType[T], json_str: str, module_scope: Optional[types.ModuleType] = None) -> T:
data = json.loads(json_str)
return cls.from_dict(data, module_scope)

@classmethod
def from_dict(cls: Type[T], data: Dict[str, Any], module_scope: Optional[types.ModuleType] = None) -> T:
def from_dict(cls: TypingType[T], data: Dict[str, Any], module_scope: Optional[types.ModuleType] = None) -> T:
decoder = DataclassJSONDecoder(module_scope or sys.modules[cls.__module__])
return decoder.decode(data, cls)
4 changes: 2 additions & 2 deletions python/tests/test_model_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
TestStepResult,
TestStepStarted,
Timestamp,
Type,
PickleStepType,
)

resource_path = Path(__file__).parent.absolute() / "data"
Expand Down Expand Up @@ -118,7 +118,7 @@
uri="samples/minimal/minimal.feature",
name="cukes",
language="en",
steps=[PickleStep(ast_node_ids=["1"], id="3", type=Type.context, text="I have 42 cukes in my belly")],
steps=[PickleStep(ast_node_ids=["1"], id="3", type=PickleStepType.context, text="I have 42 cukes in my belly")],
tags=[],
ast_node_ids=["2"],
),
Expand Down

0 comments on commit 2b02397

Please sign in to comment.