Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit c7af5c6

Browse files
authored
Merge pull request #15 from AbdelrhmanBassiouny/main
Role, BinaryPredicate, Performance
2 parents 2d00442 + c37e6bd commit c7af5c6

42 files changed

Lines changed: 1825 additions & 825 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/eql/old_examples/example_with_concatenate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Below is a minimal, self-contained example that mirrors the behavior tested in t
99

1010
```python
1111
from dataclasses import dataclass, field
12-
from typing import List
12+
from typing_extensions import List
1313

1414
from krrood.entity_query_language import symbolic_mode, let, concatenate, not_, in_, entity, an, From, symbol
1515

examples/eql/old_examples/example_with_flatten.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In this example, we place a single "cabinet" view into `world.views`. The cabine
99

1010
```python
1111
from dataclasses import dataclass, field
12-
from typing import List
12+
from typing_extensions import List
1313

1414
from krrood.entity_query_language import a, set_of, symbolic_mode, let, flatten, symbol
1515

examples/eql/old_examples/example_with_for_all.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Below is a minimal, self-contained example that mirrors the behavior used in tes
66

77
```python
88
from dataclasses import dataclass, field
9-
from typing import List
9+
from typing_extensions import List
1010

1111
from krrood.entity_query_language import symbolic_mode, let, entity, an, From, the, for_all, symbol
1212

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass, Field
4+
from abc import ABC, abstractmethod
5+
from dataclasses import fields as dc_fields
6+
7+
from typing_extensions import Dict, Iterable, List, Type, Optional, TYPE_CHECKING
8+
9+
10+
@dataclass
11+
class DiscoveredAttribute:
12+
"""Attribute discovered on a class."""
13+
14+
field: Field
15+
"""The dataclass field object that is wrapped."""
16+
public_name: Optional[str] = None
17+
"""The public name of the field."""
18+
19+
def __post_init__(self):
20+
if self.public_name is None:
21+
self.public_name = self.field.name
22+
23+
def __hash__(self) -> int:
24+
return hash(self.field)
25+
26+
27+
@dataclass
28+
class AttributeIntrospector(ABC):
29+
"""Strategy that discovers class attributes for diagramming.
30+
31+
Implementations return the set of dataclass-backed attributes that
32+
should appear on a class diagram, including their public names.
33+
"""
34+
35+
@abstractmethod
36+
def discover(self, owner_cls: Type) -> List[DiscoveredAttribute]:
37+
"""Return discovered attributes for `owner_cls`.
38+
39+
The `field` of each result must be a dataclass `Field` belonging to
40+
`owner_cls`, while `public_name` is how it should be addressed and displayed.
41+
"""
42+
raise NotImplementedError
43+
44+
45+
@dataclass
46+
class DataclassOnlyIntrospector(AttributeIntrospector):
47+
"""Discover only public dataclass fields (no leading underscore)."""
48+
49+
def discover(self, owner_cls: Type) -> List[DiscoveredAttribute]:
50+
result: List[DiscoveredAttribute] = []
51+
for f in dc_fields(owner_cls):
52+
if not f.name.startswith("_"):
53+
result.append(DiscoveredAttribute(public_name=f.name, field=f))
54+
return result

0 commit comments

Comments
 (0)