ovld 0.4.0__tar.gz → 0.4.1__tar.gz

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.
Files changed (140) hide show
  1. {ovld-0.4.0 → ovld-0.4.1}/PKG-INFO +4 -1
  2. {ovld-0.4.0 → ovld-0.4.1}/pyproject.toml +6 -6
  3. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/__init__.py +1 -0
  4. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/core.py +0 -6
  5. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/mro.py +27 -6
  6. ovld-0.4.1/src/ovld/version.py +1 -0
  7. ovld-0.4.1/tests/test_mro.py +51 -0
  8. {ovld-0.4.0 → ovld-0.4.1}/tests/test_ovld.py +8 -0
  9. ovld-0.4.0/src/ovld/version.py +0 -1
  10. {ovld-0.4.0 → ovld-0.4.1}/.bsync-snap-20220324145902.852076 +0 -0
  11. {ovld-0.4.0 → ovld-0.4.1}/.envrc +0 -0
  12. {ovld-0.4.0 → ovld-0.4.1}/.github/workflows/python-package.yml +0 -0
  13. {ovld-0.4.0 → ovld-0.4.1}/.gitignore +0 -0
  14. {ovld-0.4.0 → ovld-0.4.1}/.python-version +0 -0
  15. {ovld-0.4.0 → ovld-0.4.1}/.readthedocs.yaml +0 -0
  16. {ovld-0.4.0 → ovld-0.4.1}/LICENSE +0 -0
  17. {ovld-0.4.0 → ovld-0.4.1}/README.md +0 -0
  18. {ovld-0.4.0 → ovld-0.4.1}/add.py +0 -0
  19. {ovld-0.4.0 → ovld-0.4.1}/anal.py +0 -0
  20. {ovld-0.4.0 → ovld-0.4.1}/bench/requirements.txt +0 -0
  21. {ovld-0.4.0 → ovld-0.4.1}/bench.py +0 -0
  22. {ovld-0.4.0 → ovld-0.4.1}/benchd.py +0 -0
  23. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/__init__.py +0 -0
  24. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/common.py +0 -0
  25. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_add.py +0 -0
  26. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_ast.py +0 -0
  27. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_calc.py +0 -0
  28. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_fib.py +0 -0
  29. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_multer.py +0 -0
  30. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_trivial.py +0 -0
  31. {ovld-0.4.0 → ovld-0.4.1}/benchmarks/test_tweaknum.py +0 -0
  32. {ovld-0.4.0 → ovld-0.4.1}/cloz.py +0 -0
  33. {ovld-0.4.0 → ovld-0.4.1}/data.py +0 -0
  34. {ovld-0.4.0 → ovld-0.4.1}/didi.py +0 -0
  35. {ovld-0.4.0 → ovld-0.4.1}/docs/compare.md +0 -0
  36. {ovld-0.4.0 → ovld-0.4.1}/docs/dependent.md +0 -0
  37. {ovld-0.4.0 → ovld-0.4.1}/docs/features.md +0 -0
  38. {ovld-0.4.0 → ovld-0.4.1}/docs/index.md +0 -0
  39. {ovld-0.4.0 → ovld-0.4.1}/docs/types.md +0 -0
  40. {ovld-0.4.0 → ovld-0.4.1}/docs/usage.md +0 -0
  41. {ovld-0.4.0 → ovld-0.4.1}/doo.py +0 -0
  42. {ovld-0.4.0 → ovld-0.4.1}/edges.py +0 -0
  43. {ovld-0.4.0 → ovld-0.4.1}/explore.py +0 -0
  44. {ovld-0.4.0 → ovld-0.4.1}/facto.py +0 -0
  45. {ovld-0.4.0 → ovld-0.4.1}/gen_comparison_table.py +0 -0
  46. {ovld-0.4.0 → ovld-0.4.1}/gentest.py +0 -0
  47. {ovld-0.4.0 → ovld-0.4.1}/hello.py +0 -0
  48. {ovld-0.4.0 → ovld-0.4.1}/hntest.py +0 -0
  49. {ovld-0.4.0 → ovld-0.4.1}/klos.py +0 -0
  50. {ovld-0.4.0 → ovld-0.4.1}/mkdocs.yml +0 -0
  51. {ovld-0.4.0 → ovld-0.4.1}/nxt.py +0 -0
  52. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.0-py3-none-any.whl +0 -0
  53. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.0.tar.gz +0 -0
  54. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.1-py3-none-any.whl +0 -0
  55. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.1.tar.gz +0 -0
  56. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.2-py3-none-any.whl +0 -0
  57. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.2.tar.gz +0 -0
  58. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.3-py3-none-any.whl +0 -0
  59. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.3.tar.gz +0 -0
  60. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.4-py3-none-any.whl +0 -0
  61. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.4.tar.gz +0 -0
  62. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.5-py3-none-any.whl +0 -0
  63. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.5.tar.gz +0 -0
  64. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.6-py3-none-any.whl +0 -0
  65. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.6.tar.gz +0 -0
  66. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.7-py3-none-any.whl +0 -0
  67. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.7.tar.gz +0 -0
  68. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.8-py3-none-any.whl +0 -0
  69. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.8.tar.gz +0 -0
  70. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.9-py3-none-any.whl +0 -0
  71. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.1.9.tar.gz +0 -0
  72. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.0-py3-none-any.whl +0 -0
  73. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.0.tar.gz +0 -0
  74. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.1-py3-none-any.whl +0 -0
  75. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.1.tar.gz +0 -0
  76. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.10-py3-none-any.whl +0 -0
  77. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.10.tar.gz +0 -0
  78. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.11-py3-none-any.whl +0 -0
  79. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.11.tar.gz +0 -0
  80. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.2-py3-none-any.whl +0 -0
  81. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.2.tar.gz +0 -0
  82. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.3-py3-none-any.whl +0 -0
  83. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.3.tar.gz +0 -0
  84. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.4-py3-none-any.whl +0 -0
  85. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.4.tar.gz +0 -0
  86. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.5-py3-none-any.whl +0 -0
  87. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.5.tar.gz +0 -0
  88. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.6-py3-none-any.whl +0 -0
  89. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.6.tar.gz +0 -0
  90. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.7-py3-none-any.whl +0 -0
  91. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.7.tar.gz +0 -0
  92. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.8-py3-none-any.whl +0 -0
  93. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.8.tar.gz +0 -0
  94. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.9-py3-none-any.whl +0 -0
  95. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.2.9.tar.gz +0 -0
  96. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.0-py3-none-any.whl +0 -0
  97. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.0.tar.gz +0 -0
  98. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.1-py3-none-any.whl +0 -0
  99. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.1.tar.gz +0 -0
  100. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.2-py3-none-any.whl +0 -0
  101. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.2.tar.gz +0 -0
  102. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.3-py3-none-any.whl +0 -0
  103. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.3.tar.gz +0 -0
  104. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.4-py3-none-any.whl +0 -0
  105. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.4.tar.gz +0 -0
  106. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.5-py3-none-any.whl +0 -0
  107. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.5.tar.gz +0 -0
  108. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.8-py3-none-any.whl +0 -0
  109. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.8.tar.gz +0 -0
  110. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.9-py3-none-any.whl +0 -0
  111. {ovld-0.4.0 → ovld-0.4.1}/old-dist/ovld-0.3.9.tar.gz +0 -0
  112. {ovld-0.4.0 → ovld-0.4.1}/one_two_three.py +0 -0
  113. {ovld-0.4.0 → ovld-0.4.1}/outoftheway.toml +0 -0
  114. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/dependent.py +0 -0
  115. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/recode.py +0 -0
  116. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/typemap.py +0 -0
  117. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/types.py +0 -0
  118. {ovld-0.4.0 → ovld-0.4.1}/src/ovld/utils.py +0 -0
  119. {ovld-0.4.0 → ovld-0.4.1}/stuff.md +0 -0
  120. {ovld-0.4.0 → ovld-0.4.1}/tb.py +0 -0
  121. {ovld-0.4.0 → ovld-0.4.1}/tensor.py +0 -0
  122. {ovld-0.4.0 → ovld-0.4.1}/tests/__init__.py +0 -0
  123. {ovld-0.4.0 → ovld-0.4.1}/tests/modules/gingerbread.py +0 -0
  124. {ovld-0.4.0 → ovld-0.4.1}/tests/test_dependent.py +0 -0
  125. {ovld-0.4.0 → ovld-0.4.1}/tests/test_examples.py +0 -0
  126. {ovld-0.4.0 → ovld-0.4.1}/tests/test_global.py +0 -0
  127. {ovld-0.4.0 → ovld-0.4.1}/tests/test_ovld/test_display.txt +0 -0
  128. {ovld-0.4.0 → ovld-0.4.1}/tests/test_ovld/test_doc.txt +0 -0
  129. {ovld-0.4.0 → ovld-0.4.1}/tests/test_ovld/test_doc2.txt +0 -0
  130. {ovld-0.4.0 → ovld-0.4.1}/tests/test_ovld/test_method_doc.txt +0 -0
  131. {ovld-0.4.0 → ovld-0.4.1}/tests/test_typemap.py +0 -0
  132. {ovld-0.4.0 → ovld-0.4.1}/tests/test_types.py +0 -0
  133. {ovld-0.4.0 → ovld-0.4.1}/tests/test_utils.py +0 -0
  134. {ovld-0.4.0 → ovld-0.4.1}/todo.q +0 -0
  135. {ovld-0.4.0 → ovld-0.4.1}/toot.py +0 -0
  136. {ovld-0.4.0 → ovld-0.4.1}/typo.py +0 -0
  137. {ovld-0.4.0 → ovld-0.4.1}/uv.lock +0 -0
  138. {ovld-0.4.0 → ovld-0.4.1}/world.yaml +0 -0
  139. {ovld-0.4.0 → ovld-0.4.1}/x.py +0 -0
  140. {ovld-0.4.0 → ovld-0.4.1}/zaggo +0 -0
@@ -1,7 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ovld
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Overloading Python functions
5
+ Project-URL: Homepage, https://ovld.readthedocs.io/en/latest/
6
+ Project-URL: Documentation, https://ovld.readthedocs.io/en/latest/
7
+ Project-URL: Repository, https://github.com/breuleux/ovld
5
8
  Author-email: Olivier Breuleux <breuleux@gmail.com>
6
9
  License-Expression: MIT
7
10
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ovld"
3
- version = "0.4.0"
3
+ version = "0.4.1"
4
4
  description = "Overloading Python functions"
5
5
  authors = [
6
6
  { name = "Olivier Breuleux", email = "breuleux@gmail.com" }
@@ -8,10 +8,13 @@ authors = [
8
8
  dependencies = []
9
9
  readme = "README.md"
10
10
  license = "MIT"
11
- homepage = "https://github.com/breuleux/ovld"
12
- repository = "https://github.com/breuleux/ovld"
13
11
  requires-python = ">= 3.9"
14
12
 
13
+ [project.urls]
14
+ Homepage = "https://ovld.readthedocs.io/en/latest/"
15
+ Documentation = "https://ovld.readthedocs.io/en/latest/"
16
+ Repository = "https://github.com/breuleux/ovld"
17
+
15
18
  [build-system]
16
19
  requires = ["hatchling"]
17
20
  build-backend = "hatchling.build"
@@ -41,9 +44,6 @@ line-length = 80
41
44
  extend-select = ["I"]
42
45
  ignore = ["E241", "F722", "E501", "E203", "F811", "F821"]
43
46
 
44
- [tool.ruff.lint.per-file-ignores]
45
- "__init__.py" = ["F401", "F403"]
46
-
47
47
  [tool.pytest.ini_options]
48
48
  minversion = "6.0"
49
49
  addopts = "--benchmark-columns=median,min,max"
@@ -70,4 +70,5 @@ __all__ = [
70
70
  "keyword_decorator",
71
71
  "call_next",
72
72
  "recurse",
73
+ "__version__",
73
74
  ]
@@ -20,12 +20,6 @@ from .typemap import MultiTypeMap, is_type_of_type
20
20
  from .types import normalize_type
21
21
  from .utils import UsageError, keyword_decorator
22
22
 
23
- try:
24
- from types import UnionType
25
- except ImportError: # pragma: no cover
26
- UnionType = None
27
-
28
-
29
23
  _current_id = itertools.count()
30
24
 
31
25
 
@@ -25,6 +25,16 @@ class TypeRelationship:
25
25
  matches: bool = None
26
26
 
27
27
 
28
+ def _issubclass(t1, t2):
29
+ try:
30
+ return issubclass(t1, t2)
31
+ except TypeError:
32
+ try:
33
+ return isinstance(t1, t2)
34
+ except TypeError: # pragma: no cover
35
+ return False
36
+
37
+
28
38
  def typeorder(t1, t2):
29
39
  """Order relation between two types.
30
40
 
@@ -56,6 +66,8 @@ def typeorder(t1, t2):
56
66
  o2 = getattr(t2, "__origin__", None)
57
67
 
58
68
  if o2 is typing.Union:
69
+ if t1 is typing.Union:
70
+ return Order.MORE
59
71
  compare = [
60
72
  x for t in t2.__args__ if (x := typeorder(t1, t)) is not Order.NONE
61
73
  ]
@@ -105,8 +117,8 @@ def typeorder(t1, t2):
105
117
  # Not sure when t1 != t2 and that happens
106
118
  return Order.SAME
107
119
 
108
- sx = issubclass(t1, t2)
109
- sy = issubclass(t2, t1)
120
+ sx = _issubclass(t1, t2)
121
+ sy = _issubclass(t2, t1)
110
122
  if sx and sy: # pragma: no cover
111
123
  # Not sure when t1 != t2 and that happens
112
124
  return Order.SAME
@@ -136,14 +148,23 @@ def subclasscheck(t1, t2):
136
148
  o2 = getattr(t2, "__origin__", None)
137
149
 
138
150
  if o2 is typing.Union:
139
- return any(subclasscheck(t1, t) for t in t2.__args__)
151
+ return t1 is typing.Union or any(
152
+ subclasscheck(t1, t) for t in t2.__args__
153
+ )
140
154
  elif o1 is typing.Union:
141
- return all(subclasscheck(t, t2) for t in t1.__args__)
155
+ return t2 is typing.Union or all(
156
+ subclasscheck(t, t2) for t in t1.__args__
157
+ )
158
+
159
+ if not isinstance(o1, type):
160
+ o1 = None
161
+ if not isinstance(o2, type):
162
+ o2 = None
142
163
 
143
164
  if o1 or o2:
144
165
  o1 = o1 or t1
145
166
  o2 = o2 or t2
146
- if issubclass(o1, o2):
167
+ if _issubclass(o1, o2):
147
168
  if o2 is t2: # pragma: no cover
148
169
  return True
149
170
  else:
@@ -157,7 +178,7 @@ def subclasscheck(t1, t2):
157
178
  else:
158
179
  return False
159
180
  else:
160
- return issubclass(t1, t2)
181
+ return _issubclass(t1, t2)
161
182
 
162
183
 
163
184
  def sort_types(cls, avail):
@@ -0,0 +1 @@
1
+ version = "0.4.1"
@@ -0,0 +1,51 @@
1
+ try:
2
+ from types import UnionType
3
+ except ImportError: # pragma: no cover
4
+ UnionType = None
5
+
6
+ import sys
7
+ from typing import Union
8
+
9
+ from ovld.mro import Order, subclasscheck, typeorder
10
+
11
+
12
+ class A:
13
+ pass
14
+
15
+
16
+ class B(A):
17
+ pass
18
+
19
+
20
+ def test_subclasscheck():
21
+ assert subclasscheck(B, A)
22
+ assert not subclasscheck(A, B)
23
+ assert subclasscheck(A, A)
24
+ assert subclasscheck(A, object)
25
+ assert subclasscheck(A, Union[A, int])
26
+ assert subclasscheck(int, Union[A, int])
27
+
28
+
29
+ def test_subclasscheck_generic():
30
+ assert subclasscheck(list[int], list[int])
31
+ assert subclasscheck(list[int], list[object])
32
+ assert not subclasscheck(list[object], list[int])
33
+
34
+
35
+ def test_subclasscheck_type():
36
+ assert subclasscheck(type[int], type[object])
37
+
38
+
39
+ def test_subclasscheck_type_union():
40
+ if sys.version_info >= (3, 10):
41
+ assert subclasscheck(type[int | str], type[UnionType])
42
+ assert subclasscheck(type[Union[int, str]], type[Union])
43
+ assert subclasscheck(type[Union], object)
44
+ assert not subclasscheck(object, type[Union])
45
+
46
+
47
+ def test_typeorder_type_union():
48
+ if sys.version_info >= (3, 10):
49
+ assert typeorder(type[int | str], type[UnionType]) is Order.LESS
50
+ assert typeorder(type[Union[int, str]], type[Union]) is Order.LESS
51
+ assert typeorder(object, type[Union]) is Order.MORE
@@ -1560,6 +1560,14 @@ def test_keywords_recurse():
1560
1560
  assert f([1, 2, 3], factor=3) == [3, 6, 9]
1561
1561
 
1562
1562
 
1563
+ def test_passing_types_to_normal_func():
1564
+ @ovld
1565
+ def f(x):
1566
+ return x
1567
+
1568
+ assert f(list[int]) == list[int]
1569
+
1570
+
1563
1571
  def test_doc(file_regression):
1564
1572
  @ovld
1565
1573
  def mushroom(x: int):
@@ -1 +0,0 @@
1
- version = "0.4.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes