IncludeCPP 3.7.26__py3-none-any.whl → 3.7.28__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
includecpp/__init__.py CHANGED
@@ -2,7 +2,7 @@ from .core.cpp_api import CppApi
2
2
  from .core import cssl_bridge as CSSL
3
3
  import warnings
4
4
 
5
- __version__ = "3.7.26"
5
+ __version__ = "3.7.28"
6
6
  __all__ = ["CppApi", "CSSL"]
7
7
 
8
8
  # Module-level cache for C++ modules
@@ -205,6 +205,11 @@ class CSSLBuiltins:
205
205
  self._functions['isavailable'] = self.builtin_isavailable
206
206
  self._functions['instance::exists'] = self.builtin_isavailable # Alias
207
207
 
208
+ # Python interop functions
209
+ self._functions['python::pythonize'] = self.builtin_python_pythonize
210
+ self._functions['python::wrap'] = self.builtin_python_pythonize # Alias
211
+ self._functions['python::export'] = self.builtin_python_pythonize # Alias
212
+
208
213
  # Regex functions
209
214
  self._functions['match'] = self.builtin_match
210
215
  self._functions['search'] = self.builtin_search
@@ -2445,6 +2450,211 @@ class CSSLBuiltins:
2445
2450
 
2446
2451
  return None
2447
2452
 
2453
+ # ============= Python Interop Functions =============
2454
+
2455
+ def builtin_python_pythonize(self, cssl_instance: Any) -> Any:
2456
+ """Convert a CSSL class instance to a Python-usable object.
2457
+
2458
+ This allows CSSL classes to be returned and used in Python code
2459
+ with proper attribute access and method calls.
2460
+
2461
+ Usage in CSSL:
2462
+ class Greeter {
2463
+ string name;
2464
+
2465
+ Greeter(string n) {
2466
+ this->name = n;
2467
+ }
2468
+
2469
+ string sayHello() {
2470
+ return "Hello, " + this->name + "!";
2471
+ }
2472
+
2473
+ void setName(string newName) {
2474
+ this->name = newName;
2475
+ }
2476
+
2477
+ string getName() {
2478
+ return this->name;
2479
+ }
2480
+ }
2481
+
2482
+ greeter = new Greeter("World");
2483
+ pyclass = python::pythonize(greeter);
2484
+ parameter.return(pyclass);
2485
+
2486
+ Usage in Python:
2487
+ from includecpp import CSSL
2488
+
2489
+ cssl = CSSL.CsslLang()
2490
+ greeter = cssl.run('''
2491
+ class Greeter { ... }
2492
+ g = new Greeter("World");
2493
+ parameter.return(python::pythonize(g));
2494
+ ''')
2495
+
2496
+ # Now use it like a normal Python object:
2497
+ print(greeter.name) # "World"
2498
+ print(greeter.sayHello()) # "Hello, World!"
2499
+ greeter.setName("Python")
2500
+ print(greeter.getName()) # "Python"
2501
+
2502
+ Args:
2503
+ cssl_instance: A CSSLInstance object (created via 'new ClassName()')
2504
+
2505
+ Returns:
2506
+ PythonizedCSSLInstance - A Python-friendly wrapper
2507
+ """
2508
+ from .cssl_types import CSSLInstance, CSSLClass
2509
+
2510
+ if cssl_instance is None:
2511
+ return None
2512
+
2513
+ # Already pythonized
2514
+ if isinstance(cssl_instance, PythonizedCSSLInstance):
2515
+ return cssl_instance
2516
+
2517
+ # Must be a CSSLInstance
2518
+ if not isinstance(cssl_instance, CSSLInstance):
2519
+ # If it's a dict, wrap it as a simple object
2520
+ if isinstance(cssl_instance, dict):
2521
+ return PythonizedDict(cssl_instance)
2522
+ # Return as-is for primitives
2523
+ return cssl_instance
2524
+
2525
+ return PythonizedCSSLInstance(cssl_instance, self.runtime)
2526
+
2527
+
2528
+ class PythonizedCSSLInstance:
2529
+ """Python wrapper for CSSL class instances.
2530
+
2531
+ Provides Pythonic attribute access and method calling for CSSL objects.
2532
+ """
2533
+
2534
+ def __init__(self, instance: Any, runtime: Any = None):
2535
+ # Use object.__setattr__ to avoid triggering our custom __setattr__
2536
+ object.__setattr__(self, '_cssl_instance', instance)
2537
+ object.__setattr__(self, '_cssl_runtime', runtime)
2538
+ object.__setattr__(self, '_cssl_class_name', instance._class.name if hasattr(instance, '_class') else 'Unknown')
2539
+
2540
+ def __getattr__(self, name: str) -> Any:
2541
+ """Get member or method from CSSL instance."""
2542
+ if name.startswith('_'):
2543
+ raise AttributeError(f"'{self._cssl_class_name}' has no attribute '{name}'")
2544
+
2545
+ instance = object.__getattribute__(self, '_cssl_instance')
2546
+ runtime = object.__getattribute__(self, '_cssl_runtime')
2547
+
2548
+ # Check for member variable first
2549
+ if instance.has_member(name):
2550
+ value = instance.get_member(name)
2551
+ # Recursively pythonize nested CSSL instances
2552
+ from .cssl_types import CSSLInstance
2553
+ if isinstance(value, CSSLInstance):
2554
+ return PythonizedCSSLInstance(value, runtime)
2555
+ return value
2556
+
2557
+ # Check for method
2558
+ method = instance.get_method(name)
2559
+ if method is not None:
2560
+ # Return a callable wrapper for the method
2561
+ return PythonizedMethod(instance, name, method, runtime)
2562
+
2563
+ raise AttributeError(f"'{self._cssl_class_name}' has no attribute '{name}'")
2564
+
2565
+ def __setattr__(self, name: str, value: Any) -> None:
2566
+ """Set member value on CSSL instance."""
2567
+ if name.startswith('_'):
2568
+ object.__setattr__(self, name, value)
2569
+ return
2570
+
2571
+ instance = object.__getattribute__(self, '_cssl_instance')
2572
+ instance.set_member(name, value)
2573
+
2574
+ def __repr__(self) -> str:
2575
+ class_name = object.__getattribute__(self, '_cssl_class_name')
2576
+ instance = object.__getattribute__(self, '_cssl_instance')
2577
+ members = list(instance._members.keys()) if hasattr(instance, '_members') else []
2578
+ return f"<PythonizedCSSL '{class_name}' members={members}>"
2579
+
2580
+ def __dir__(self) -> list:
2581
+ """List available attributes."""
2582
+ instance = object.__getattribute__(self, '_cssl_instance')
2583
+ members = list(instance._members.keys()) if hasattr(instance, '_members') else []
2584
+ methods = list(instance._class.methods.keys()) if hasattr(instance._class, 'methods') else []
2585
+ return members + methods
2586
+
2587
+ def _to_dict(self) -> dict:
2588
+ """Convert to Python dictionary."""
2589
+ instance = object.__getattribute__(self, '_cssl_instance')
2590
+ result = {}
2591
+ for name, value in instance._members.items():
2592
+ from .cssl_types import CSSLInstance
2593
+ if isinstance(value, CSSLInstance):
2594
+ result[name] = PythonizedCSSLInstance(value, None)._to_dict()
2595
+ else:
2596
+ result[name] = value
2597
+ return result
2598
+
2599
+
2600
+ class PythonizedMethod:
2601
+ """Wrapper that makes CSSL methods callable from Python."""
2602
+
2603
+ def __init__(self, instance: Any, method_name: str, method_ast: Any, runtime: Any):
2604
+ self._instance = instance
2605
+ self._method_name = method_name
2606
+ self._method_ast = method_ast
2607
+ self._runtime = runtime
2608
+
2609
+ def __call__(self, *args, **kwargs) -> Any:
2610
+ """Call the CSSL method with arguments."""
2611
+ if self._runtime is None:
2612
+ raise RuntimeError(f"Cannot call method '{self._method_name}' - no runtime available")
2613
+
2614
+ # Execute the method through the runtime
2615
+ # Pass the method AST node, not the method name
2616
+ result = self._runtime._call_method(self._instance, self._method_ast, list(args), kwargs)
2617
+
2618
+ # Pythonize the result if it's a CSSL instance
2619
+ from .cssl_types import CSSLInstance
2620
+ if isinstance(result, CSSLInstance):
2621
+ return PythonizedCSSLInstance(result, self._runtime)
2622
+
2623
+ return result
2624
+
2625
+ def __repr__(self) -> str:
2626
+ return f"<method '{self._method_name}' of '{self._instance._class.name}'>"
2627
+
2628
+
2629
+ class PythonizedDict:
2630
+ """Simple wrapper for dict objects with attribute access."""
2631
+
2632
+ def __init__(self, data: dict):
2633
+ object.__setattr__(self, '_data', data)
2634
+
2635
+ def __getattr__(self, name: str) -> Any:
2636
+ data = object.__getattribute__(self, '_data')
2637
+ if name in data:
2638
+ value = data[name]
2639
+ if isinstance(value, dict):
2640
+ return PythonizedDict(value)
2641
+ return value
2642
+ raise AttributeError(f"No attribute '{name}'")
2643
+
2644
+ def __setattr__(self, name: str, value: Any) -> None:
2645
+ if name.startswith('_'):
2646
+ object.__setattr__(self, name, value)
2647
+ return
2648
+ data = object.__getattribute__(self, '_data')
2649
+ data[name] = value
2650
+
2651
+ def __repr__(self) -> str:
2652
+ data = object.__getattribute__(self, '_data')
2653
+ return f"<PythonizedDict {data}>"
2654
+
2655
+ def _to_dict(self) -> dict:
2656
+ return object.__getattribute__(self, '_data')
2657
+
2448
2658
 
2449
2659
  # Module-level convenience functions
2450
2660
  _default_builtins: Optional[CSSLBuiltins] = None
@@ -1164,5 +1164,43 @@
1164
1164
  "}"
1165
1165
  ],
1166
1166
  "description": "Function with selectable modifier combinations"
1167
+ },
1168
+ "Python Pythonize": {
1169
+ "prefix": ["python::pythonize", "pythonize"],
1170
+ "body": "python::pythonize(${1:instance})$0",
1171
+ "description": "Convert CSSL class instance to Python-usable object"
1172
+ },
1173
+ "Return Pythonized Class": {
1174
+ "prefix": "returnpython",
1175
+ "body": [
1176
+ "${1:instance} = new ${2:ClassName}(${3:args});",
1177
+ "pyobj = python::pythonize(${1});",
1178
+ "parameter.return(pyobj);"
1179
+ ],
1180
+ "description": "Create class instance and return as Python object"
1181
+ },
1182
+ "Class with Python Export": {
1183
+ "prefix": "pyclass",
1184
+ "body": [
1185
+ "class ${1:ClassName} {",
1186
+ "\t${2:string} ${3:name};",
1187
+ "",
1188
+ "\t${1}(${4:params}) {",
1189
+ "\t\tthis->${3} = ${5:value};",
1190
+ "\t}",
1191
+ "",
1192
+ "\t${6:string} get${3/(.*)/${1:/capitalize}/}() {",
1193
+ "\t\treturn this->${3};",
1194
+ "\t}",
1195
+ "",
1196
+ "\tvoid set${3/(.*)/${1:/capitalize}/}(${2} newValue) {",
1197
+ "\t\tthis->${3} = newValue;",
1198
+ "\t}",
1199
+ "}",
1200
+ "",
1201
+ "${7:obj} = new ${1}(${8:args});",
1202
+ "parameter.return(python::pythonize(${7}));$0"
1203
+ ],
1204
+ "description": "Create a class and export as Python object"
1167
1205
  }
1168
1206
  }
@@ -319,6 +319,14 @@
319
319
  {
320
320
  "name": "support.function.namespace.combo.cssl",
321
321
  "match": "\\bcombo::(filterdb|blocked|like)\\b"
322
+ },
323
+ {
324
+ "name": "support.function.namespace.python.cssl",
325
+ "match": "\\bpython::(pythonize|wrap|export)\\b"
326
+ },
327
+ {
328
+ "name": "support.function.namespace.filter.cssl",
329
+ "match": "\\bfilter::(register|unregister|list|exists)\\b"
322
330
  }
323
331
  ]
324
332
  },
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: IncludeCPP
3
- Version: 3.7.26
3
+ Version: 3.7.28
4
4
  Summary: Professional C++ Python bindings with type-generic templates, pystubs and native threading
5
5
  Home-page: https://github.com/liliassg/IncludeCPP
6
6
  Author: Lilias Hatterscheidt
@@ -853,3 +853,55 @@ cssl.run('''
853
853
  printl(@version);
854
854
  ''')
855
855
  ```
856
+
857
+ ## Return CSSL Classes to Python
858
+
859
+ Use `python::pythonize()` to convert CSSL class instances into Python-usable objects:
860
+
861
+ ```python
862
+ from includecpp import CSSL
863
+
864
+ cssl = CSSL.CsslLang()
865
+
866
+ # Create and return a CSSL class as a Python object
867
+ greeter = cssl.run('''
868
+ class Greeter {
869
+ string name;
870
+
871
+ Greeter(string n) {
872
+ this->name = n;
873
+ }
874
+
875
+ string sayHello() {
876
+ return "Hello, " + this->name + "!";
877
+ }
878
+
879
+ void setName(string newName) {
880
+ this->name = newName;
881
+ }
882
+
883
+ string getName() {
884
+ return this->name;
885
+ }
886
+ }
887
+
888
+ instance = new Greeter("World");
889
+ pyclass = python::pythonize(instance);
890
+ parameter.return(pyclass);
891
+ ''')
892
+
893
+ # Now use it like a normal Python object!
894
+ print(greeter.name) # "World"
895
+ print(greeter.sayHello()) # "Hello, World!"
896
+ greeter.setName("Python")
897
+ print(greeter.getName()) # "Python"
898
+ print(greeter.name) # "Python"
899
+ ```
900
+
901
+ ### Aliases
902
+
903
+ - `python::pythonize(instance)` - Main function
904
+ - `python::wrap(instance)` - Alias
905
+ - `python::export(instance)` - Alias
906
+
907
+ All three do the same thing: wrap a CSSL class instance for Python use.
@@ -1,4 +1,4 @@
1
- includecpp/__init__.py,sha256=tg-Rg63h9qYhHvpAknQ6sig3-2vJE121Nt0YcM6jhCo,1673
1
+ includecpp/__init__.py,sha256=pu-NnXVrmFySEIy47R4t7MyCatn3ewzjtaF7d5YDUfc,1673
2
2
  includecpp/__init__.pyi,sha256=uSDYlbqd2TinmrdepmE_zvN25jd3Co2cgyPzXgDpopM,7193
3
3
  includecpp/__main__.py,sha256=d6QK0PkvUe1ENofpmHRAg3bwNbZr8PiRscfI3-WRfVg,72
4
4
  includecpp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -21,7 +21,7 @@ includecpp/core/project_ui.py,sha256=la2EQZKmUkJGuJxnbs09hH1ZhBh9bfndo6okzZsk2dQ
21
21
  includecpp/core/settings_ui.py,sha256=B2SlwgdplF2KiBk5UYf2l8Jjifjd0F-FmBP0DPsVCEQ,11798
22
22
  includecpp/core/cssl/CSSL_DOCUMENTATION.md,sha256=47sUPO-FMq_8_CrJBZFoFBgSO3gSi5zoB1Xp7oeifho,40773
23
23
  includecpp/core/cssl/__init__.py,sha256=scDXRBNK2L6A8qmlpNyaqQj6BFcSfPInBlucdeNfMF0,1975
24
- includecpp/core/cssl/cssl_builtins.py,sha256=r-FX4WQeKxerkepqodIiwhtL_kxxa4PJym_WyWIwA_s,92290
24
+ includecpp/core/cssl/cssl_builtins.py,sha256=B_ggaV4zE1kejphXmo0-_XKFyxU4BWv_g0j_KzHpLJI,100225
25
25
  includecpp/core/cssl/cssl_builtins.pyi,sha256=3ai2V4LyhzPBhAKjRRf0rLVu_bg9ECmTfTkdFKM64iA,127430
26
26
  includecpp/core/cssl/cssl_events.py,sha256=nupIcXW_Vjdud7zCU6hdwkQRQ0MujlPM7Tk2u7eDAiY,21013
27
27
  includecpp/core/cssl/cssl_modules.py,sha256=cUg0-zdymMnWWTsA_BUrW5dx4R04dHpKcUhm-Wfiwwo,103006
@@ -42,11 +42,11 @@ includecpp/vscode/cssl/language-configuration.json,sha256=61Q00cKI9may5L8YpxMmvf
42
42
  includecpp/vscode/cssl/package.json,sha256=Zu2QoTE0OVCCDUHp1hc7kN2NBbFs60bX-LLGMpXz25M,4853
43
43
  includecpp/vscode/cssl/images/cssl.png,sha256=BxAGsnfS0ZzzCvqV6Zb1OAJAZpDUoXlR86MsvUGlSZw,510
44
44
  includecpp/vscode/cssl/images/cssl_pl.png,sha256=z4WMk7g6YCTbUUbSFk343BO6yi_OmNEVYkRenWGydwM,799
45
- includecpp/vscode/cssl/snippets/cssl.snippets.json,sha256=4zHOPWNX2_Pk2j2ms84Cx4wv8H089oio371F3vXohXE,36005
46
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json,sha256=XKRLBOHlCqDDnGPvmNHDQPsIMR1UD9PBaJIlgZOiPqM,21173
47
- includecpp-3.7.26.dist-info/licenses/LICENSE,sha256=fWCsGGsiWZir0UzDd20Hh-3wtRyk1zqUntvtVuAWhvc,1093
48
- includecpp-3.7.26.dist-info/METADATA,sha256=DcEjed5M_UJAX_YqHNtwFk6MtdMDHHpi91Mqcb_ents,21277
49
- includecpp-3.7.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
- includecpp-3.7.26.dist-info/entry_points.txt,sha256=6A5Mif9gi0139Bf03W5plAb3wnAgbNaEVe1HJoGE-2o,59
51
- includecpp-3.7.26.dist-info/top_level.txt,sha256=RFUaR1KG-M6mCYwP6w4ydP5Cgc8yNbP78jxGAvyjMa8,11
52
- includecpp-3.7.26.dist-info/RECORD,,
45
+ includecpp/vscode/cssl/snippets/cssl.snippets.json,sha256=uV3nHJyQ5f7Pr3FzfbQT2VZOEY3AlGs4wrmqe884jm4,37372
46
+ includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json,sha256=ArCRc_G54kiKGh6WEd4CbmR-SX1X9BOcp3Y0hwZcw44,21543
47
+ includecpp-3.7.28.dist-info/licenses/LICENSE,sha256=fWCsGGsiWZir0UzDd20Hh-3wtRyk1zqUntvtVuAWhvc,1093
48
+ includecpp-3.7.28.dist-info/METADATA,sha256=9zrNxfjy1cYZ8rTRrq6pdEX6hROhfS7GSa2D4fwOpvE,22511
49
+ includecpp-3.7.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ includecpp-3.7.28.dist-info/entry_points.txt,sha256=6A5Mif9gi0139Bf03W5plAb3wnAgbNaEVe1HJoGE-2o,59
51
+ includecpp-3.7.28.dist-info/top_level.txt,sha256=RFUaR1KG-M6mCYwP6w4ydP5Cgc8yNbP78jxGAvyjMa8,11
52
+ includecpp-3.7.28.dist-info/RECORD,,