named
Advanced tools
+167
| from builtins import hasattr as has_attribute | ||
| from typing import Any | ||
| from typing_extensions import Protocol, TypeGuard, runtime_checkable | ||
| __all__ = ( | ||
| # named | ||
| "NAME", | ||
| "Named", | ||
| "get_name", | ||
| "get_type_name", | ||
| "has_name", | ||
| "is_named", | ||
| "set_name", | ||
| "set_type_name", | ||
| # moduled | ||
| "MODULE", | ||
| "Moduled", | ||
| "get_module", | ||
| "get_type_module", | ||
| "has_module", | ||
| "is_moduled", | ||
| "set_module", | ||
| "set_type_module", | ||
| ) | ||
| NAME = "__name__" | ||
| """The literal `__name__` string.""" | ||
| @runtime_checkable | ||
| class Named(Protocol): | ||
| """The named protocol for types that contain the `__name__` attribute.""" | ||
| __name__: str | ||
| def get_name(item: Named) -> str: | ||
| """Fetches the `__name__` of the [`Named`][named.typing.Named] `item`. | ||
| Arguments: | ||
| item: The item to fetch the name of. | ||
| Returns: | ||
| The name of the item. | ||
| """ | ||
| return item.__name__ | ||
| def set_name(item: Named, name: str) -> None: | ||
| """Sets the `__name__` of the [`Named`][named.typing.Named] `item`. | ||
| Arguments: | ||
| item: The item to set the name of. | ||
| name: The name to set on the item. | ||
| """ | ||
| item.__name__ = name | ||
| def get_type_name(item: Any) -> str: | ||
| """Fetches the `__name__` of the `item` type. | ||
| Arguments: | ||
| item: The item to fetch the type name of. | ||
| Returns: | ||
| The name of the item type. | ||
| """ | ||
| return get_name(type(item)) # type: ignore | ||
| def set_type_name(item: Any, name: str) -> None: | ||
| """Sets the `__name__` of the `item` type. | ||
| Arguments: | ||
| item: The item to set the type name of. | ||
| name: The name to set on the item type. | ||
| """ | ||
| set_name(type(item), name) # type: ignore | ||
| def is_named(item: Any) -> TypeGuard[Named]: | ||
| """Checks if the `item` implements the [`Named`][named.typing.Named] protocol. | ||
| Arguments: | ||
| item: The item to check. | ||
| Returns: | ||
| Whether the item implements the [`Named`][named.typing.Named] protocol. | ||
| """ | ||
| return has_attribute(item, NAME) | ||
| has_name = is_named | ||
| """An alias of [`is_named`][named.typing.is_named].""" | ||
| MODULE = "__module__" | ||
| """The literal `__module__` string.""" | ||
| @runtime_checkable | ||
| class Moduled(Protocol): | ||
| """The moduled protocol for types that contain the `__module__` attribute.""" | ||
| __module__: str | ||
| def get_module(item: Moduled) -> str: | ||
| """Fetches the `__module__` of the [`Moduled`][named.typing.Moduled] `item`. | ||
| Arguments: | ||
| item: The item to fetch the module of. | ||
| Returns: | ||
| The module of the item. | ||
| """ | ||
| return item.__module__ | ||
| def set_module(item: Moduled, module: str) -> None: | ||
| """Sets the `__module__` of the [`Moduled`][named.typing.Moduled] `item`. | ||
| Arguments: | ||
| item: The item to set the module of. | ||
| module: The module to set on the item. | ||
| """ | ||
| item.__module__ = module | ||
| def get_type_module(item: Any) -> str: | ||
| """Fetches the `__module__` of the `item` type. | ||
| Arguments: | ||
| item: The item to fetch the type module of. | ||
| Returns: | ||
| The module of the item type. | ||
| """ | ||
| return get_module(type(item)) # type: ignore | ||
| def set_type_module(item: Any, module: str) -> None: | ||
| """Sets the `__module__` of the `item` type. | ||
| Arguments: | ||
| item: The item to set the type module of. | ||
| module: The module to set on the item type. | ||
| """ | ||
| set_module(type(item), module) # type: ignore | ||
| def is_moduled(item: Any) -> TypeGuard[Moduled]: | ||
| """Checks if the `item` implements the [`Moduled`][named.typing.Moduled] protocol. | ||
| Arguments: | ||
| item: The item to check. | ||
| Returns: | ||
| Whether the item implements the [`Moduled`][named.typing.Moduled] protocol. | ||
| """ | ||
| return has_attribute(item, MODULE) | ||
| has_module = is_moduled | ||
| """An alias of [`is_moduled`][named.typing.is_moduled].""" |
+10
-2
@@ -26,5 +26,5 @@ """Named types. | ||
| __license__ = "MIT" | ||
| __version__ = "1.2.0" | ||
| __version__ = "1.3.0" | ||
| from named.typing import ( | ||
| from named.core import ( | ||
| MODULE, | ||
@@ -42,2 +42,6 @@ NAME, | ||
| is_named, | ||
| set_module, | ||
| set_name, | ||
| set_type_module, | ||
| set_type_name, | ||
| ) | ||
@@ -53,2 +57,4 @@ | ||
| "is_named", | ||
| "set_name", | ||
| "set_type_name", | ||
| # moduled | ||
@@ -61,2 +67,4 @@ "MODULE", | ||
| "is_moduled", | ||
| "set_module", | ||
| "set_type_module", | ||
| ) |
+2
-2
| Metadata-Version: 2.1 | ||
| Name: named | ||
| Version: 1.2.0 | ||
| Version: 1.3.0 | ||
| Summary: Named types. | ||
@@ -76,3 +76,3 @@ Home-page: https://github.com/nekitdev/named | ||
| [tool.poetry.dependencies] | ||
| named = "^1.2.0" | ||
| named = "^1.3.0" | ||
| ``` | ||
@@ -79,0 +79,0 @@ |
+2
-2
| [tool.poetry] | ||
| name = "named" | ||
| version = "1.2.0" | ||
| version = "1.3.0" | ||
| description = "Named types." | ||
@@ -138,3 +138,3 @@ authors = ["nekitdev"] | ||
| name = "named" | ||
| version = "1.2.0" | ||
| version = "1.3.0" | ||
| url = "https://github.com/nekitdev/named" | ||
@@ -141,0 +141,0 @@ directory = "changes" |
+1
-1
@@ -47,3 +47,3 @@ # `named` | ||
| [tool.poetry.dependencies] | ||
| named = "^1.2.0" | ||
| named = "^1.3.0" | ||
| ``` | ||
@@ -50,0 +50,0 @@ |
-123
| from builtins import hasattr as has_attribute | ||
| from typing import Any | ||
| from typing_extensions import Protocol, TypeGuard, runtime_checkable | ||
| __all__ = ( | ||
| # named | ||
| "NAME", | ||
| "Named", | ||
| "get_name", | ||
| "get_type_name", | ||
| "has_name", | ||
| "is_named", | ||
| # moduled | ||
| "MODULE", | ||
| "Moduled", | ||
| "get_module", | ||
| "get_type_module", | ||
| "has_module", | ||
| "is_moduled", | ||
| ) | ||
| NAME = "__name__" | ||
| """The literal `__name__` string.""" | ||
| @runtime_checkable | ||
| class Named(Protocol): | ||
| """The named protocol for types that contain the `__name__` attribute.""" | ||
| __name__: str | ||
| def get_name(item: Named) -> str: | ||
| """Fetches the `__name__` of the [`Named`][named.typing.Named] `item`. | ||
| Arguments: | ||
| item: The item to fetch the name of. | ||
| Returns: | ||
| The name of the item. | ||
| """ | ||
| return item.__name__ | ||
| def get_type_name(item: Any) -> str: | ||
| """Fetches the `__name__` of the `item` type. | ||
| Arguments: | ||
| item: The item to fetch the type name of. | ||
| Returns: | ||
| The name of the item type. | ||
| """ | ||
| return get_name(type(item)) # type: ignore | ||
| def is_named(item: Any) -> TypeGuard[Named]: | ||
| """Checks if the `item` implements the [`Named`][named.typing.Named] protocol. | ||
| Arguments: | ||
| item: The item to check. | ||
| Returns: | ||
| Whether the item implements the [`Named`][named.typing.Named] protocol. | ||
| """ | ||
| return has_attribute(item, NAME) | ||
| has_name = is_named | ||
| """An alias of [`is_named`][named.typing.is_named].""" | ||
| MODULE = "__module__" | ||
| """The literal `__module__` string.""" | ||
| @runtime_checkable | ||
| class Moduled(Protocol): | ||
| """The moduled protocol for types that contain the `__module__` attribute.""" | ||
| __module__: str | ||
| def get_module(item: Moduled) -> str: | ||
| """Fetches the `__module__` of the [`Moduled`][named.typing.Moduled] `item`. | ||
| Arguments: | ||
| item: The item to fetch the module of. | ||
| Returns: | ||
| The module of the item. | ||
| """ | ||
| return item.__module__ | ||
| def get_type_module(item: Any) -> str: | ||
| """Fetches the `__module__` of the `item` type. | ||
| Arguments: | ||
| item: The item to fetch the type module of. | ||
| Returns: | ||
| The module of the item type. | ||
| """ | ||
| return get_module(type(item)) # type: ignore | ||
| def is_moduled(item: Any) -> TypeGuard[Moduled]: | ||
| """Checks if the `item` implements the [`Moduled`][named.typing.Moduled] protocol. | ||
| Arguments: | ||
| item: The item to check. | ||
| Returns: | ||
| Whether the item implements the [`Moduled`][named.typing.Moduled] protocol. | ||
| """ | ||
| return has_attribute(item, MODULE) | ||
| has_module = is_moduled | ||
| """An alias of [`is_moduled`][named.typing.is_moduled].""" |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
16613
8.5%173
30.08%