Essentially I'd like to create "subclass" of typing.Annotated that
always sets the metadata to 'abstract'. Thus far, I haven't found a
way to do this, as typing.Annotated can't be subclassed.
Alright, so here's the deal: you're right that typing.Annotated
# The factory function
def AbstractClassVariable(type_: T) -> Any:
return Annotated[type_, abstract]
Option 2: Custom Wrapper Class
(Note: I have mail delivery disabled for this list and read it through GMane. Please copy me on any responses, so that I can respond with
proper threading.)
From the things that I probably shouldn't spend my free time on
department ...
As background, I'm working on a project that is going to involve a bunch
of abstract classes and dynamic types, and I've found that Python's
existing abstract class implementation leaves a lot to be desired, particularly the inability to create abstract class variables and class methods. Having been seduced by the Siren song of Python's flexibility,
I've been rolling my own implementation.
Now to my question.
I'm currently using annotations to create abstract class variables, for example:
class Foo(object, metaclass=AbstractType):
acv: Annotated[int, abstract]
('abstract' is simply a unique "flag" object.)
This works just fine, but it's somewhat un-idiomatic. What I'd like to
be able to do is create my own type, so that I could do something like
this:
class Foo(object, metaclass=AbstractType):
acv: AbstractClassVariable[int]
Essentially I'd like to create "subclass" of typing.Annotated that
always sets the metadata to 'abstract'. Thus far, I haven't found a
way to do this, as typing.Annotated can't be subclassed.
Anyone have any ideas?
--
========================================================================
If your user interface is intuitive in retrospect ... it isn't intuitive ========================================================================
--
https://mail.python.org/mailman/listinfo/python-list
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 148:07:21 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
33 files (6,120K bytes) |
Messages: | 2,410,932 |