Skip to content

fix bug #323

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

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/codegen/sdk/core/symbol_groups/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Parent = TypeVar("Parent")


class Collection(SymbolGroup[Child, Parent], MutableSequence[Child], Generic[Child, Parent]):

Check failure on line 22 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Definition of "__contains__" in base class "Editable" is incompatible with definition in base class "Sequence" [misc]

Check failure on line 22 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Definition of "__contains__" in base class "Editable" is incompatible with definition in base class "Container" [misc]

Check failure on line 22 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Type argument "Parent" of "SymbolGroup" must be a subtype of "Editable[Any]" [type-var]
"""Ordered collection of nodes
Attributes:
_bracket_size: Number of characters wrapping the collection
Expand Down Expand Up @@ -47,7 +47,7 @@
if children is not None:
self._init_children(children)

def _init_children(self, symbols: list[Child]):

Check failure on line 50 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "_init_children" incompatible with supertype "SymbolGroup" [override]
"""Call this after setting self._symbols."""
if self.ts_node.start_point[0] != self.ts_node.end_point[0] and symbols:
# This is a multiline collection.
Expand All @@ -70,7 +70,7 @@
if isinstance(key, slice):
assert isinstance(value, Iterable)
for idx, item in zip(range(key.start, key.stop, key.step), value):
self[idx] = item

Check failure on line 73 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: No overload variant of "__setitem__" of "Collection" matches argument types "int", "object" [call-overload]
else:
assert not isinstance(value, Iterable)
if isinstance(value, Editable):
Expand All @@ -94,7 +94,7 @@
return self._elements + self._inserts_till()

@writer
def remove(self, value: Child | None = None, *args, **kwargs) -> None:

Check failure on line 97 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 of "remove" is incompatible with supertype "SymbolGroup"; supertype defines the argument type as "bool" [override]
"""Removes an element from a Collection.

Deletes the specified element from the Collection by calling its remove method. If no value is specified,
Expand All @@ -112,7 +112,8 @@
# For example, let's remove all occurrences of the value instead of just the first one
if value is None:
super().remove(*args, **kwargs)
value.remove(*args, **kwargs)
else:
value.remove(*args, **kwargs)

def _inserts_till(self, max_idx: int | None = None) -> int:
"""Find the number of pending inserts until max_idx."""
Expand Down Expand Up @@ -240,7 +241,7 @@
Returns:
None
"""
return Editable.edit(self, *args, **kwargs) # HACK: keep start/end brackets

Check failure on line 244 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: Value of type variable "Parent" of "edit" of "Editable" cannot be "Parent" [type-var]

@property
@reader
Expand Down Expand Up @@ -276,4 +277,4 @@
self._reversed.clear()

def _smart_remove(self, child, *args, **kwargs) -> bool:
return self.parent._smart_remove(self, child, *args, **kwargs)

Check failure on line 280 in src/codegen/sdk/core/symbol_groups/collection.py

View workflow job for this annotation

GitHub Actions / mypy

error: "Parent" has no attribute "_smart_remove" [attr-defined]
Loading