primeira versão transcreve audio

This commit is contained in:
Impacte AI
2024-11-29 13:51:10 -03:00
commit 449d6cffe4
1549 changed files with 427969 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
"""propcache: An accelerated property cache for Python classes."""
from typing import TYPE_CHECKING, List
_PUBLIC_API = ("cached_property", "under_cached_property")
__version__ = "0.2.0"
__all__ = ()
# Imports have moved to `propcache.api` in 0.2.0+.
# This module is now a facade for the API.
if TYPE_CHECKING:
from .api import cached_property as cached_property # noqa: F401
from .api import under_cached_property as under_cached_property # noqa: F401
def _import_facade(attr: str) -> object:
"""Import the public API from the `api` module."""
if attr in _PUBLIC_API:
from . import api # pylint: disable=import-outside-toplevel
return getattr(api, attr)
raise AttributeError(f"module '{__package__}' has no attribute '{attr}'")
def _dir_facade() -> List[str]:
"""Include the public API in the module's dir() output."""
return [*_PUBLIC_API, *globals().keys()]
__getattr__ = _import_facade
__dir__ = _dir_facade

View File

@@ -0,0 +1,39 @@
import os
import sys
from typing import TYPE_CHECKING
__all__ = ("cached_property", "under_cached_property")
NO_EXTENSIONS = bool(os.environ.get("PROPCACHE_NO_EXTENSIONS")) # type: bool
if sys.implementation.name != "cpython":
NO_EXTENSIONS = True
# isort: off
if TYPE_CHECKING:
from ._helpers_py import cached_property as cached_property_py
from ._helpers_py import under_cached_property as under_cached_property_py
cached_property = cached_property_py
under_cached_property = under_cached_property_py
elif not NO_EXTENSIONS: # pragma: no branch
try:
from ._helpers_c import cached_property as cached_property_c # type: ignore[attr-defined, unused-ignore] # noqa: E501
from ._helpers_c import under_cached_property as under_cached_property_c # type: ignore[attr-defined, unused-ignore] # noqa: E501
cached_property = cached_property_c
under_cached_property = under_cached_property_c
except ImportError: # pragma: no cover
from ._helpers_py import cached_property as cached_property_py
from ._helpers_py import under_cached_property as under_cached_property_py
cached_property = cached_property_py # type: ignore[assignment, misc]
under_cached_property = under_cached_property_py
else:
from ._helpers_py import cached_property as cached_property_py
from ._helpers_py import under_cached_property as under_cached_property_py
cached_property = cached_property_py # type: ignore[assignment, misc]
under_cached_property = under_cached_property_py
# isort: on

View File

@@ -0,0 +1,92 @@
# cython: language_level=3
import sys
import types
if sys.version_info >= (3, 9):
GenericAlias = types.GenericAlias
else:
def GenericAlias(cls):
return cls
cdef _sentinel = object()
cdef class under_cached_property:
"""Use as a class method decorator. It operates almost exactly like
the Python `@property` decorator, but it puts the result of the
method it decorates into the instance dict after the first call,
effectively replacing the function it decorates with an instance
variable. It is, in Python parlance, a data descriptor.
"""
cdef object wrapped
cdef object name
def __init__(self, wrapped):
self.wrapped = wrapped
self.name = wrapped.__name__
@property
def __doc__(self):
return self.wrapped.__doc__
def __get__(self, inst, owner):
if inst is None:
return self
cdef dict cache = inst._cache
val = cache.get(self.name, _sentinel)
if val is _sentinel:
val = self.wrapped(inst)
cache[self.name] = val
return val
def __set__(self, inst, value):
raise AttributeError("cached property is read-only")
cdef class cached_property:
"""Use as a class method decorator. It operates almost exactly like
the Python `@property` decorator, but it puts the result of the
method it decorates into the instance dict after the first call,
effectively replacing the function it decorates with an instance
variable. It is, in Python parlance, a data descriptor.
"""
cdef object wrapped
cdef object name
def __init__(self, wrapped):
self.wrapped = wrapped
self.name = None
@property
def __doc__(self):
return self.wrapped.__doc__
def __set_name__(self, owner, name):
if self.name is None:
self.name = name
elif name != self.name:
raise TypeError(
"Cannot assign the same cached_property to two different names "
f"({self.name!r} and {name!r})."
)
def __get__(self, inst, owner):
if inst is None:
return self
if self.name is None:
raise TypeError(
"Cannot use cached_property instance"
" without calling __set_name__ on it.")
cdef dict cache = inst.__dict__
val = cache.get(self.name, _sentinel)
if val is _sentinel:
val = self.wrapped(inst)
cache[self.name] = val
return val
__class_getitem__ = classmethod(GenericAlias)

View File

@@ -0,0 +1,71 @@
"""Various helper functions."""
import sys
from functools import cached_property
from typing import (
Any,
Callable,
Dict,
Generic,
Optional,
Protocol,
Type,
TypeVar,
Union,
overload,
)
__all__ = ("under_cached_property", "cached_property")
if sys.version_info >= (3, 11):
from typing import Self
else:
Self = Any
_T = TypeVar("_T")
class _TSelf(Protocol, Generic[_T]):
_cache: Dict[str, _T]
class under_cached_property(Generic[_T]):
"""Use as a class method decorator.
It operates almost exactly like
the Python `@property` decorator, but it puts the result of the
method it decorates into the instance dict after the first call,
effectively replacing the function it decorates with an instance
variable. It is, in Python parlance, a data descriptor.
"""
def __init__(self, wrapped: Callable[..., _T]) -> None:
self.wrapped = wrapped
self.__doc__ = wrapped.__doc__
self.name = wrapped.__name__
@overload
def __get__( # pragma: no cover
self, inst: None, owner: Optional[Type[Any]] = None
) -> Self: ... # pragma: no cover
@overload
def __get__( # pragma: no cover
self, inst: _TSelf[_T], owner: Optional[Type[Any]] = None
) -> _T: ... # pragma: no cover
def __get__(
self, inst: Optional[_TSelf[_T]], owner: Optional[Type[Any]] = None
) -> Union[_T, Self]:
if inst is None:
return self
try:
return inst._cache[self.name]
except KeyError:
val = self.wrapped(inst)
inst._cache[self.name] = val
return val
def __set__(self, inst: _TSelf[_T], value: _T) -> None:
raise AttributeError("cached property is read-only")

View File

@@ -0,0 +1,8 @@
"""Public API of the property caching library."""
from ._helpers import cached_property, under_cached_property
__all__ = (
"cached_property",
"under_cached_property",
)

View File

@@ -0,0 +1 @@
# Placeholder