chielonewctle / plain-abc Goto Github PK
View Code? Open in Web Editor NEWAnother ABC implementation without metaclass.
License: MIT License
Another ABC implementation without metaclass.
License: MIT License
PlainABC Enum mixin with .name and .value properties raises the following error:
class WordSizeEnumOfPrimitiveTypes(IWordSizeEnum, StrEnum):
../.pyenv/versions/3.11.1/lib/python3.11/enum.py:552: in __new__
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
.venv/lib/python3.11/site-packages/plain_abc.py:133: in __init_subclass__
raise MissingImplError(cls, missing)
E plain_abc.MissingImplError: missing implementation in <enum 'WordSizeEnumOfPrimitiveTypes'> for name, value
Although the properties seems to be there in Enum class: https://github.com/python/cpython/blob/main/Lib/enum.py#L1247
When switching 'property' to 'enum.property' decorator the error extends to Enum member properties:
E plain_abc.MissingImplError: missing implementation in <enum 'WordSizeEnumOfPrimitiveTypes'> for name, value, x32...
I got it (almost) working with the Protocol (python/typing#1522). But it requires metaclass conflict resolution as always... I would be grateful if you could help to investigate the issue or suggest a workaround.
import enum
from abc import abstractmethod
from typing import Literal
from plain_abc import PlainABC
class IWordSizeEnum(PlainABC):
@enum.property
@abstractmethod
def x32(self) -> Literal["x32"]:
...
@enum.property
@abstractmethod
def x64(self) -> Literal["x64"]:
...
@property
@abstractmethod
def name(self) -> str:
...
@property
@abstractmethod
def value(self) -> str:
...
class WordSizeEnumOfPrimitiveTypes(IWordSizeEnum, StrEnum):
x32 = "x32"
x64 = "x64"
def type_check_word_size_enum(word_size_enum: IWordSizeEnum):
word_size_enum.x32.value
I am unable to use inheritance with PlainABC to extend base class with more abstract methods. The same works fine with ABC.
from abc import abstractmethod
from typing import Literal
from plain_abc import PlainABC
class IMediaType(PlainABC):
pass
class IApplicationPython(IMediaType):
@property
@abstractmethod
def media_type(self) -> Literal["application/prs.binary+python"]:
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dstokar3/panda/.venv/lib/python3.11/site-packages/plain_abc.py", line 133, in __init_subclass__
raise MissingImplError(cls, missing)
plain_abc.MissingImplError: missing implementation in <class '__main__.IApplicationPython'> for media_type
Thank you for your effort to avoid metaclass conflicts with abstract classes! Brilliant idea!
I tried to use PlanABC with Enum and it does not work as expected:
from abc import abstractmethod
from typing import Literal
from enum import Enum
from plain_abc import PlainABC
class IWordSizeEnum(PlainABC):
@property
@abstractmethod
def x32(self) -> Literal["x32"]:
...
@property
@abstractmethod
def x64(self) -> Literal["x64"]:
...
class OSWordSizeEnum(IWordSizeEnum, Enum):
x32 = "x32"
x64 = "x64"
----- Output -----
class OSWordSizeEnum(IWordSizeEnum, Enum):
../.pyenv/versions/3.11.1/lib/python3.11/enum.py:552: in __new__
enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
.venv/lib/python3.11/site-packages/plain_abc.py:105: in __init_subclass__
current_signature = tp._plain_abc_member_signature(name, attr)
.venv/lib/python3.11/site-packages/plain_abc.py:85: in _plain_abc_member_signature
raise TypeError(
E TypeError: unknown type of member x32: OSWordSizeEnum.x32 to get the signature
Should _plain_abc_member_signature(...) return signature for any type?
pip install from github:
pip install plain-abc@git+https://github.com/ChieloNewctle/plain-abc
... fails with the following error:
<snip>
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/build.py", line 58, in build_wheel
return os.path.basename(next(builder.build(directory=wheel_directory, versions=['standard'])))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 155, in build
artifact = version_api[version](directory, **build_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 407, in build_standard
for included_file in self.recurse_included_files():
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 176, in recurse_included_files
yield from self.recurse_selected_project_files()
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 180, in recurse_selected_project_files
if self.config.only_include:
^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/config.py", line 781, in only_include
only_include = only_include_config.get('only-include', self.default_only_include()) or self.packages
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 235, in default_only_include
return self.default_file_selection_options.only_include
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/dstokar3/.pyenv/versions/3.11.1/lib/python3.11/functools.py", line 1001, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-yzpu3x59/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 223, in default_file_selection_options
raise ValueError(message)
ValueError: Unable to determine which files to ship inside the wheel using the following heuristics: https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection
At least one file selection option must be defined in the `tool.hatch.build.targets.wheel` table, see: https://hatch.pypa.io/latest/config/build/
As an example, if you intend to ship a directory named `foo` that resides within a `src` directory located at the root of your project, you can define the following:
[tool.hatch.build.targets.wheel]
packages = ["src/foo"]
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.