-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest of changes to extract commits from
- Loading branch information
Showing
59 changed files
with
1,784 additions
and
1,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from typing import TypeAlias | ||
|
||
from omnipy.modules.frozen.models import NestedFrozenDictsOrTuplesModel | ||
from omnipy.modules.general.models import Model | ||
from tests.modules.general.cases.raw.examples import (e_complex_key_dict, | ||
e_int_key_dict, | ||
e_none_key_dict, | ||
ej_frozendict_iterable_scalar, | ||
ej_frozendict_iterable_scalar_empty, | ||
ej_frozendict_wrong_scalar, | ||
ej_tuple_iterable_scalar, | ||
ej_tuple_wrong_scalar, | ||
ej_type, | ||
f_complex, | ||
f_dict, | ||
f_frozendict, | ||
f_int, | ||
f_list, | ||
f_none, | ||
f_set, | ||
f_str, | ||
f_tuple) | ||
|
||
FSK: TypeAlias = int | str | complex # for keys | ||
FSV: TypeAlias = None | int | str | complex # for values | ||
|
||
|
||
def run_nested_frozen_dicts_or_tuples_model() -> None: | ||
_two_level_list: list[FSV | list[FSV] | dict[str, FSV]] = \ | ||
f_list + [list(f_list)] + [dict(f_dict)] | ||
_two_level_dict: dict[str, str | list[FSV] | dict[str, FSV]] = \ | ||
{'a': f_str, 'b': list(f_list), 'c': dict(f_dict)} | ||
|
||
number_model = Model[int](123) | ||
|
||
print(number_model.snapshot_holder._deepcopy_memo) | ||
|
||
number_model.snapshot_holder._deepcopy_memo.clear() | ||
|
||
print(number_model.snapshot_holder._deepcopy_memo) | ||
|
||
nested_frozen_dicts_or_tuples = ( | ||
list(f_list + [list(f_list), dict(f_dict), list(_two_level_list), dict(_two_level_dict)])) | ||
nested_frozen_dicts_or_tuples_model = NestedFrozenDictsOrTuplesModel( | ||
nested_frozen_dicts_or_tuples) | ||
|
||
print(len(number_model.snapshot_holder._deepcopy_memo)) | ||
k = 0 | ||
v = 0 | ||
for k, v in number_model.snapshot_holder._deepcopy_memo.items(): | ||
print(f'{k}: {v}') | ||
del k | ||
del v | ||
|
||
del nested_frozen_dicts_or_tuples_model | ||
number_model.snapshot_holder.delete_scheduled_deepcopy_content_ids() | ||
print(number_model.snapshot_holder._deepcopy_memo) | ||
|
||
assert len(number_model.snapshot_holder._deepcopy_memo) == 0 | ||
|
||
|
||
run_nested_frozen_dicts_or_tuples_model() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def omnipy_import() -> None: | ||
import omnipy | ||
import omnipy._dynamic_all | ||
omnipy.data | ||
from omnipy import Model | ||
import omnipy.data | ||
|
||
# omnipy._dynamic_all.data | ||
|
||
|
||
omnipy_import() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Generic, get_args, get_origin, Literal | ||
|
||
from pydantic.fields import UndefinedType | ||
from typing_extensions import TypeVar | ||
|
||
from omnipy import Model | ||
|
||
D = TypeVar('D', default=object) | ||
S = TypeVar('S', default=object) | ||
T = TypeVar('T', default=Literal[',']) | ||
|
||
|
||
class Param(Model[UndefinedType | S | D], Generic[S, D]): | ||
@classmethod | ||
def _parse_data(cls, data: UndefinedType | S | D): | ||
override, default = get_args(cls.outer_type(with_args=True))[1:3] | ||
print(f'default: {repr(default)}, override: {repr(override)}, data: {repr(data)}') | ||
assert get_origin(default) == Literal | ||
target = override if get_origin(override) == Literal else default | ||
print( | ||
f'data: {repr(data)}, target: {repr(target)}, check: {type(data) is not UndefinedType and data != target}' | ||
) | ||
if type(data) is not UndefinedType and data != target: | ||
print('I amm asserting!') | ||
raise AssertionError( | ||
f'Data other than the default or override literals are not allowed: {data}') | ||
return target | ||
|
||
|
||
DefaultDelim = Literal[','] | ||
|
||
|
||
class DelimitParam(Param[S, DefaultDelim], Generic[S]): | ||
... | ||
|
||
|
||
class Y(Model[list[str] | tuple[str, DelimitParam]]): | ||
... | ||
|
||
|
||
class ValueWithParam(Model[tuple[DelimitParam[S], T]], Generic[T, S]): | ||
@classmethod | ||
def _parse_data(cls, data: tuple[T, DelimitParam[S]]): | ||
print(f'data: {repr(data)}') | ||
return data | ||
|
||
|
||
class D(Model[T], Generic[T]): | ||
... | ||
|
||
|
||
D[Literal['asd']]() | ||
|
||
|
||
class Splitter(Model[list[str] | str | Model[T]], Generic[T]): | ||
... | ||
|
||
|
||
class A(Model[tuple[T, S]], Generic[T, S]): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import cProfile | ||
from importlib import import_module | ||
import os | ||
import pstats | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
script_path = os.path.abspath(sys.argv[1]) | ||
project_path = os.path.abspath(__file__ + '/../..') | ||
|
||
print(f'script_path: {script_path}') | ||
print(f'project_path: {project_path}') | ||
|
||
assert script_path.startswith(project_path) | ||
module = '.'.join(script_path.split('.')[0][len(project_path) + 1:].split('/')) | ||
|
||
# print(f'package: {package}') | ||
print(f'module: {module}') | ||
|
||
sys.path.append(project_path) | ||
|
||
mod = import_module(module) | ||
|
||
profiler = cProfile.Profile() | ||
profiler.enable() | ||
|
||
mod.run() | ||
|
||
profiler.disable() | ||
stats = pstats.Stats(profiler).sort_stats('cumtime') | ||
stats.dump_stats('latest4.pstats') | ||
print('dumped') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.