Deutsch English Français Italiano |
<mailman.96.1738320096.2912.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Fabien LUCE <fabienluce@gmail.com> Newsgroups: comp.lang.python Subject: Re: Any way to "subclass" typing.Annotated? Date: Fri, 31 Jan 2025 11:41:22 +0100 Lines: 52 Message-ID: <mailman.96.1738320096.2912.python-list@python.org> References: <f0ab4e78-15eb-4f24-8185-46c6e411b261@gmail.com> <CAHX3m-dELjCPYg8zn=_zpo_XAGGebwF1RyRmEi_zOgH+H4y60Q@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: news.uni-berlin.de P2e+2HtLghvSC9yB/BCtAwrtkiOLlugHHVfgkST0rfOw== Cancel-Lock: sha1:6YlXohtHVeOkQtKgrBNWr+PakAQ= sha256:UoS5+gZgUSgcp/75mjQmAaM9K0/HRZLr/IsR5KsF14s= Return-Path: <fabienluce@gmail.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=hLr2reAl; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'this:': 0.03; 'bunch': 0.05; "python's": 0.05; 'url:mailman': 0.09; 'email addr:python.org>': 0.09; 'example:': 0.09; "shouldn't": 0.09; 'url:listinfo': 0.15; '2025': 0.16; 'far,': 0.16; 'intuitive': 0.16; 'responses,': 0.16; 'somewhat': 0.16; 'subject:way': 0.16; 'variables,': 0.16; 'wrote:': 0.16; 'probably': 0.17; "can't": 0.17; 'to:addr:python-list': 0.20; 'url-ip:188.166.95.178/32': 0.20; 'url-ip:188.166.95/24': 0.20; "i've": 0.22; 'maybe': 0.22; 'url-ip:188.166/16': 0.24; "i'd": 0.24; 'to:name:python- list@python.org': 0.24; 'anyone': 0.25; 'classes': 0.26; 'interface': 0.26; "isn't": 0.27; 'email addr:python.org>': 0.28; 'tue,': 0.31; 'message-id:@mail.gmail.com': 0.31; 'disabled': 0.32; 'python-list': 0.32; 'but': 0.32; "i'm": 0.33; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'able': 0.34; 'from:addr:gmail.com': 0.34; 'particularly': 0.35; 'question.': 0.35; '...': 0.37; "skip:' 10": 0.37; 'currently': 0.37; 'using': 0.37; "it's": 0.37; 'could': 0.37; 'class': 0.37; 'way': 0.38; 'read': 0.38; 'list': 0.39; 'use': 0.39; 'this,': 0.39; 'something': 0.40; 'simply': 0.63; 'copy': 0.63; 'skip:m 20': 0.63; 'delivery': 0.64; "you'd": 0.64; 'your': 0.64; 'involve': 0.64; 'spend': 0.64; 'thus': 0.64; 'respond': 0.68; 'types,': 0.69; 'free': 0.71; 'background,': 0.84; 'email name:< ;python-list': 0.84; 'skip:= 70': 0.84; 'subject:Any': 0.84; 'type,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738320093; x=1738924893; darn=python.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=TgpN9A+mkeYez8CJiKF0grPxxjwbXy+Tc4/WaAPyj48=; b=hLr2reAlBYwv2+lLf6UAXcz5Awx+C3kQG8kTo9h4HRXlf2TAACUMF0IWU+PFKg9kM0 oG7IoYrRbl2ZeHgRTd/HjWId0XehG6Ssgr/94R2thzuWgqnLK8JwJOIYzSiUVcODBCpH DV2j5nfNpbJLJ3hc57+7jmrY/oV4yg+LIV7Ffgx1A2wvVyBCbxnMa5jofoO+bduAFx+P oh3VCEY/TCedKJzgKGuAgmm6rL3zaU/OJjr3Gx2sDaSBlxo1DtQ13ihKTzzdKnIFhoog hgBZRgSByfvlIjEqb8LBYhJdOfGw/ty3gAx7CmcpsQhF6H43VYo72baWHc5yo7n7Hh+M JXIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738320093; x=1738924893; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TgpN9A+mkeYez8CJiKF0grPxxjwbXy+Tc4/WaAPyj48=; b=OafhaVadPAuoupeGP6FgLXkL9Zxm9HrVOCiDqwVFvd6KioTrFtrP0SFNL+VOMDTd+7 tPPF6Ys2d6O6PP03ljoxWOg4ibwdi5Serkfgsl++jsoNmMN5VeMv8pdaGZwhGYueFvM9 GbHj/1cR4gYm6hFXoAwBdQXA/nI/d2kKL5aylNrVxFYoksS2vjo4AGWrj+jc9SX9f0B0 FWpNQCLQliwSu1lT09V31vhGll23s490/2DUNehBH2WgJGeYFd8c1ntdWA4EEWdQfnLQ o5YrHXhREpKESmG0B8eIuFmPPfIVUwtUEVd9fp8yF0NpG+9dKaaFp5wRQ8mYD+8dveKZ 5yGw== X-Gm-Message-State: AOJu0YwPBkwqX9nC9x8WYwIQN6HtL4XolXfHU7oOJ6cDwt/5yRSIbcXU 6QkPGVAIuj6KaxbORDQdoqMApwmEn1WeewbcLnVMkO3DIdG+C1gElrVNtTYKk9S2lejC6s0YTRR Mmhi4O7axPn+VXiGgz98Q1LBX0aLI8g== X-Gm-Gg: ASbGncsFSjwtAanXLMf3zKXoP0TzBxE4Dnz09JE+rFTaJ3GX/ncVk6JOMvPrPBddAlN hhzTKUqU0fRd6TVEhDc6kOm/g4wLbs7ViIGdrnkOnEWARncDMk8qgSL9PRRx3hEyOamm3ZXvMdA == X-Google-Smtp-Source: AGHT+IEVDAyAW9049CwCbWDZokzHiiK823csN2PVAd+cP/Zk8LoWJjyvICQEMLlNeyKUHnZhRaibXQH4PU5uR9twGJQ= X-Received: by 2002:a05:6122:10e2:b0:515:d230:f2c6 with SMTP id 71dfb90a1353d-51ebe696eb1mr1448744e0c.7.1738320093490; Fri, 31 Jan 2025 02:41:33 -0800 (PST) In-Reply-To: <f0ab4e78-15eb-4f24-8185-46c6e411b261@gmail.com> X-Gm-Features: AWEUYZknFxN0vTw82caNi2c9LF0MhO_TA2K9OlrIupB7YnLozG4Xz6ad6L60NIE X-Content-Filtered-By: Mailman/MimeDel 2.1.39 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> List-Archive: <https://mail.python.org/pipermail/python-list/> List-Post: <mailto:python-list@python.org> List-Help: <mailto:python-list-request@python.org?subject=help> List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> X-Mailman-Original-Message-ID: <CAHX3m-dELjCPYg8zn=_zpo_XAGGebwF1RyRmEi_zOgH+H4y60Q@mail.gmail.com> X-Mailman-Original-References: <f0ab4e78-15eb-4f24-8185-46c6e411b261@gmail.com> Bytes: 7385 Maybe you'd better use descriptors? On Tue, 28 Jan 2025 at 23:03, Ian Pilcher via Python-list < python-list@python.org> wrote: > (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 >