Skip to content

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-morel committed Jun 5, 2024
1 parent 81162a1 commit 883e5db
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 87 deletions.
32 changes: 16 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@
autoclass_content = "both"

sys.setrecursionlimit(500)
project = 'pyoload'
copyright = '2024, ken-morel'
author = 'ken-morel'
project = "pyoload"
copyright = "2024, ken-morel"
author = "ken-morel"

release = '2.0.0'
version = '2.0.0'
release = "2.0.0"
version = "2.0.0"

# -- General configuration

extensions = [
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
"sphinx.ext.duration",
"sphinx.ext.doctest",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
]

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
'github': ('https://github.com/', None),
"python": ("https://docs.python.org/3/", None),
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
"github": ("https://github.com/", None),
}
intersphinx_disabled_domains = ['std']
intersphinx_disabled_domains = ["std"]

templates_path = ['_templates']
templates_path = ["_templates"]

# -- Options for HTML output

html_theme = "sphinxawesome_theme"

# -- Options for EPUB output
epub_show_urls = 'footnote'
epub_show_urls = "footnote"

rst_prolog = """\
.. role:: python(code)
Expand Down
13 changes: 6 additions & 7 deletions src/pyoload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from typing import GenericAlias
from typing import Type
from typing import Union

try:
from types import NoneType
from types import NoneType
except ImportError:
NoneType = type(None)

Expand Down Expand Up @@ -351,9 +352,7 @@ def cast(val: Any, totype: Any) -> Any:
kt, vt = args
elif len(args) == 1:
kt, vt = args[0], Any
return {
Cast.cast(k, kt): Cast.cast(v, vt) for k, v in val.items()
}
return {Cast.cast(k, kt): Cast.cast(v, vt) for k, v in val.items()}
else:
sub = args[0]
return get_origin(totype)([Cast.cast(v, sub) for v in val])
Expand Down Expand Up @@ -633,7 +632,7 @@ def wrapper(*pargs, **kw):


def unannotate(func: Callable) -> Callable:
if hasattr(func, '__pyod_annotate__'):
if hasattr(func, "__pyod_annotate__"):
return func.__pyod_annotate__
else:
return func
Expand All @@ -649,11 +648,11 @@ def annotable(func: Callable) -> Callable:


def is_annotable(func):
return not hasattr(func, '__pyod_annotable__') or func.__pyod_annotable__
return not hasattr(func, "__pyod_annotable__") or func.__pyod_annotable__


def is_annoted(func):
return hasattr(func, '__pyod_annotate__')
return hasattr(func, "__pyod_annotate__")


__overloads__: dict[str, list[Callable]] = {}
Expand Down
85 changes: 38 additions & 47 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
project_dir = Path(__file__).parent

try:
long_description = (project_dir / 'README.md').read_text()
long_description = (project_dir / "README.md").read_text()
except FileNotFoundError:
try:
long_description = Path('README.md').read_text()
long_description = Path("README.md").read_text()
except FileNotFoundError:
try:
long_description = Path('/src/README.md').read_text()
long_description = Path("/src/README.md").read_text()
except FileNotFoundError:
long_description = (project_dir.parent / 'README.md').read_text()
long_description = (project_dir.parent / "README.md").read_text()

deps = ()

extra_flake8 = (
'flake8',
'flake8-commas',
'flake8-quotes',
'flake8-multiline-containers',
"flake8",
"flake8-commas",
"flake8-quotes",
"flake8-multiline-containers",
)

extra_test = (
'pytest',
'pytest-cov',
"pytest",
"pytest-cov",
)

extra_dev = (
Expand All @@ -39,62 +39,53 @@
extra_ci = (
# *extra_flake8,
*extra_test,
'coveralls',
"coveralls",
)

setup(
name='pyoload',
name="pyoload",
version=__version__,
packages=find_packages(exclude=['tests', 'tests.*']),
packages=find_packages(exclude=["tests", "tests.*"]),
project_urls={
'Documentation': 'https://pyoload.readthedocs.io/',
'Funding': 'https://ko-fi.com/kenmorel',
'Source': 'https://github.com/ken-morel/pyoload/',
'Tracker': 'https://github.com/ken-morel/pyoload/issues',
"Documentation": "https://pyoload.readthedocs.io/",
"Funding": "https://ko-fi.com/kenmorel",
"Source": "https://github.com/ken-morel/pyoload/",
"Tracker": "https://github.com/ken-morel/pyoload/issues",
},
url='https://github.com/ken-morel/pyoload',
license='MIT',
author='ken-morel',
author_email='engonken8@gmail.com',
maintainer='ken-morel',
maintainer_email='engonken8@gmail.com',
url="https://github.com/ken-morel/pyoload",
license="MIT",
author="ken-morel",
author_email="engonken8@gmail.com",
maintainer="ken-morel",
maintainer_email="engonken8@gmail.com",
description=(
'Python package for function argument overload,'
' typechecking and casting'
"Python package for function argument overload," " typechecking and casting"
),
long_description=long_description,
long_description_content_type='text/markdown',

long_description_content_type="text/markdown",
install_requires=deps,
extras_require={
'dev': extra_dev,
'ci': extra_ci,
"dev": extra_dev,
"ci": extra_ci,
},

classifiers=[
# See https://pypi.org/classifiers/

'Intended Audience :: Developers',

"Intended Audience :: Developers",
# 'Development Status :: 1 - Planning',
# 'Development Status :: 2 - Pre-Alpha',
'Development Status :: 3 - Alpha',
"Development Status :: 3 - Alpha",
# 'Development Status :: 4 - Beta',
# 'Development Status :: 5 - Production/Stable',
# 'Development Status :: 6 - Mature',
# 'Development Status :: 7 - Inactive',

'License :: OSI Approved :: MIT License',

'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',

'Natural Language :: English',

'Topic :: Software Development :: Libraries :: Python Modules',
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Natural Language :: English",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
7 changes: 7 additions & 0 deletions src/tests/logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
typeMatch vs isinstance on int:True 0.26837916ms
typeMatch vs isinstance on int:False 0.24146669ms
typeMatch on dict[str, int]*50:True 29.45430688ms
typeMatch on dict[str, int]*50:False 5.970363880000001ms
Cast str->int: 2.92456138ms
Cast complex->int | str: 0.12061774399999999ms
Cast dict[int,list[str]*10]*10->dict[str,tuple[float]]: 2.7908898460000002ms
7 changes: 4 additions & 3 deletions src/tests/test_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from pyoload import annotate

assert pyoload.__version__ == '2.0.0'
assert pyoload.__version__ == "2.0.0"


@annotate
def foo(a, b=3, c: str = 'R') -> int:
def foo(a, b=3, c: str = "R") -> int:
assert b == 3
assert isinstance(c, str)
return 3
Expand All @@ -15,5 +15,6 @@ def foo(a, b=3, c: str = 'R') -> int:
def test_annotate():
foo(2)

if __name__ == '__main__':

if __name__ == "__main__":
test_annotate()
1 change: 1 addition & 0 deletions src/tests/test_overload.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ def test_overload():
assert foo(1, 2) == 2
assert foo(1, 2, 3) == 3


if __name__ == "__main__":
test_overload()
30 changes: 16 additions & 14 deletions src/tests/test_speed.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from pyoload import typeMatch, Cast
from time import perf_counter_ns as nanos
from pathlib import Path
from pyoload import Cast
from pyoload import Union
from pyoload import typeMatch
from time import perf_counter_ns as nanos


N = 100000
NS = 10
src = Path('.').resolve().parent
src = Path(__file__).resolve().parent


def test_speed():
f = open(src / "logs.yaml", 'w')
f = open(src / "logs.yaml", "w")
speedTypeMatch(f)
speedCast(f)
f.close()
Expand All @@ -26,7 +28,7 @@ def speedTypeMatch(f):
end2 = nanos()
dt = (end - begin) - (end2 - begin2)
dt = dt / 1000 / N
print(f'typeMatch vs isinstance on int:True {dt}ms', file=f)
print(f"typeMatch vs isinstance on int:True {dt}ms", file=f)

begin = nanos()
for _ in range(N):
Expand All @@ -38,46 +40,46 @@ def speedTypeMatch(f):
end2 = nanos()
dt = (end - begin) - (end2 - begin2)
dt = dt / 1000 / N
print(f'typeMatch vs isinstance on int:False {dt}ms', file=f)
print(f"typeMatch vs isinstance on int:False {dt}ms", file=f)

obj = {str(x): x for x in range(50)}
t = dict[str, int]
begin = nanos()
for _ in range(N):
typeMatch(obj, t)
end = nanos()
dt = (end - begin)
dt = end - begin
dt = dt / 1000 / N
print(f'typeMatch on dict[str, int]*50:True {dt}ms', file=f)
print(f"typeMatch on dict[str, int]*50:True {dt}ms", file=f)

obj = {complex(x): float(x) for x in range(50)}
t = dict[str, int]
begin = nanos()
for _ in range(N):
typeMatch(obj, t)
end = nanos()
dt = (end - begin)
dt = end - begin
dt = dt / 1000 / N
print(f'typeMatch on dict[str, int]*50:False {dt}ms', file=f)
print(f"typeMatch on dict[str, int]*50:False {dt}ms", file=f)


def speedCast(f):
ct = Cast(int)

begin = nanos()
for x in range(N):
ct('3')
ct("3")
end = nanos()
dt = (end - begin) / N / 1000
print(f'Cast str->int: {dt}ms', file=f)
print(f"Cast str->int: {dt}ms", file=f)

ct = Cast(Union[int, str])
begin = nanos()
for x in range(N // NS):
ct(3j)
end = nanos()
dt = (end - begin) / N / NS / 1000
print(f'Cast complex->int | str: {dt}ms', file=f)
print(f"Cast complex->int | str: {dt}ms", file=f)

v = {x: [str(x)] * NS for x in range(NS)}
ct = Cast(dict[str, tuple[float]])
Expand All @@ -87,6 +89,6 @@ def speedCast(f):
end = nanos()
dt = (end - begin) / N / NS / 1000
print(
f'Cast dict[int,list[str]*{NS}]*{NS}->dict[str,tuple[float]]: {dt}ms',
f"Cast dict[int,list[str]*{NS}]*{NS}->dict[str,tuple[float]]: {dt}ms",
file=f,
)

0 comments on commit 883e5db

Please sign in to comment.