Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

It's computer hardware, of course it's worth having <g> -- Espy on #Debian


devel / comp.lang.python / Re: File system path annotations

SubjectAuthor
o Re: File system path annotationsRoel Schroeven

1
Re: File system path annotations

<mailman.113.1687165783.23016.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23632&group=comp.lang.python#23632

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news-2.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: roe...@roelschroeven.net (Roel Schroeven)
Newsgroups: comp.lang.python
Subject: Re: File system path annotations
Date: Mon, 19 Jun 2023 11:09:36 +0200
Lines: 59
Message-ID: <mailman.113.1687165783.23016.python-list@python.org>
References: <CAC-uhUB0mq2LmJRGwHtcZ09A1WntBPP9+FcB+D9dqQqmPK6XLQ@mail.gmail.com>
<283236db-95a3-f4cd-cf98-87792b369e52@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de e7aP7Vf9smvLoATbSTOwwA8c0DyKG2xV2Z+lap2fd+lQ==
Return-Path: <roel@roelschroeven.net>
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=roelschroeven.net header.i=@roelschroeven.net
header.b=lWHgZAme; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; 'arrays':
0.07; 'class.': 0.07; 'e.g.': 0.07; 'pep': 0.07; 'string': 0.07;
'wrong.': 0.07; 'apparently': 0.09; 'byte': 0.09; 'instances':
0.09; 'library,': 0.09; 'url-ip:151.101.0.223/32': 0.09; 'url-
ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32': 0.09;
'url-ip:151.101.64.223/32': 0.09; 'talks': 0.14; 'that.': 0.15;
'desire': 0.16; 'hint': 0.16; "isn't.": 0.16; 'odd': 0.16;
'paper,': 0.16; 'paths': 0.16; 'planet': 0.16; 'received:10.202':
0.16; 'received:10.202.2': 0.16; 'received:10.202.2.163': 0.16;
'received:10.202.2.47': 0.16; 'received:internal': 0.16;
'received:messagingengine.com': 0.16; 'runtime': 0.16; 'schreef':
0.16; 'something?': 0.16; 'specify': 0.16; 'subject:File': 0.16;
'typing': 0.16; 'url:peps': 0.16; 'python': 0.16; 'to:addr:python-
list': 0.20; 'problem,': 0.22; 'skip:_ 10': 0.22; '(and': 0.25;
'section': 0.25; 'object': 0.26; "wasn't": 0.26; 'expect': 0.28;
'header:User-Agent:1': 0.30; 'whole': 0.30; 'module': 0.31;
'think': 0.32; "doesn't": 0.32; '"this': 0.32; 'concerned': 0.32;
'objects': 0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'path':
0.33; 'work.': 0.34; 'header:In-Reply-To:1': 0.34; 'received:66':
0.35; 'people': 0.36; 'missing': 0.37; 'special': 0.37; 'using':
0.37; 'class': 0.37; 'file': 0.38; 'way': 0.38; 'quite': 0.39;
'adding': 0.39; 'enough': 0.39; 'use': 0.39; 'define': 0.40;
'something': 0.40; 'hello,': 0.40; 'should': 0.40; 'including':
0.60; 'provide': 0.60; 'finally': 0.62; 'paper': 0.62; 'url-
ip:151.101.0/24': 0.62; 'url-ip:151.101.128/24': 0.62; 'url-
ip:151.101.192/24': 0.62; 'url-ip:151.101.64/24': 0.62;
'providing': 0.63; 'url:a': 0.64; 'skip:t 20': 0.66; 'time.':
0.66; 'types': 0.67; 'please,': 0.67; 'acceptable': 0.69;
'movement': 0.69; 'only.': 0.69; 'solutions': 0.70; 'pieces':
0.70; 'living': 0.71; 'little': 0.73; 'potentially': 0.76;
'returned': 0.81; 'confirms': 0.84; 'method,': 0.84;
'represented': 0.84; 'so:': 0.84; 'adams': 0.91; 'largely': 0.91;
'that:': 0.91; 'trick': 0.91; 'union': 0.91; 'green': 0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
roelschroeven.net; h=cc:content-transfer-encoding:content-type
:content-type:date:date:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:sender:subject
:subject:to:to; s=fm1; t=1687165780; x=1687252180; bh=Tee7p8Gis/
5c6gygJRhaqr0y9Er4VxQFl68uygjTwIQ=; b=lWHgZAmeQMtKoxgfSGqJDFjxqU
wUfvyKUkh0LA5QYyoOeWW3YEl7zBWMjZAsBfSYMycKROiyJ3/ogoZtSkgcs7Z2w+
5vGCSFfHkJI5Uqleb9p/WgKoibHpPDi31JlaabZBB3qG5ionLA1w+B3sCWv/r9vO
gOBTPSSidwHIqk+G6rrDfMLlho1ttiXkz3VuCwgFPgnAAw9QCULAccLl3J6P8X37
Kjhesj+PwPGxw5+S47ZaviyqQpIEc4y4/v/NwWGmBCdoqRufU1bUlyzcSRKzh/ei
useMn5P6cyGni7PWM4VevGjtev5VBnomdqrx6JrWbs42/Y9VihsASbzD7ijw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:content-type:date:date:feedback-id:feedback-id:from:from
:in-reply-to:in-reply-to:message-id:mime-version:references
:reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy
:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1687165780; x=
1687252180; bh=Tee7p8Gis/5c6gygJRhaqr0y9Er4VxQFl68uygjTwIQ=; b=d
pWt98ONe6DevL6TVDVXlTwugx9tQMyQVXOg+gwuza5mEI4zqG18w2WWPwyb6Wf7+
UisM1nvDXHECnFPnNsgcPfhQNyWyGYW/64YLtN46vNYz2C9sWOSRc7FZziR/VIrr
z4MWEDMkT96/uqGpif6DePsn6yfKqNhhhIKRkPKxWh1wUrZ3sANJWtuZyitXRgrL
dIioi8DBaZZPLiCQANYOgpFs9gB8n7n3RtLCb3iQlnDa75aor2W6J3aKvk1Gp6O2
2+kY5VxhhkBLGblF6ZlDkWvvPTBLasmTHDyoRuH0ec0UePOfK7vwicetGkNFVwfe
VTNe0fPuyrFE2YZNCCSuw==
X-ME-Sender: <xms:VBuQZO5epVi7dqxyBtlLRwTTRPQNaQzD5T2PI6HFfUDVc92mFezalA>
<xme:VBuQZH5bEYE1fAj6K4UBPl7Swq3UYTAFRfHSAwOsZqVo7inEyjVHzJEWjhYUGe2F6
NvIiwJQub8g>
X-ME-Received: <xmr:VBuQZNeAHyAgMaDzYYG9cuSkCsA04CtcWckJuEeVetxu-jn4_mY8hHlgbC5XSa26gruCcRnbEnAAGMypu_ds590XpNQy8vu1C1K1ZcZkPFjber8>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefvddguddtucetufdoteggodetrfdotf
fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtke
ertddtfeejnecuhfhrohhmpeftohgvlhcuufgthhhrohgvvhgvnhcuoehrohgvlhesrhho
vghlshgthhhrohgvvhgvnhdrnhgvtheqnecuggftrfgrthhtvghrnhepveekvdehteefud
ejvdffgfdugfelhfetueetjeetleefudfhieegjefhjefhleffnecuffhomhgrihhnpehs
thgrtghkohhvvghrfhhlohifrdgtohhmpdgrnhihphgrthhhrdhithdpphihthhhohhnrd
horhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep
rhhovghlsehrohgvlhhstghhrhhovghvvghnrdhnvght
X-ME-Proxy: <xmx:VBuQZLJxQngxMbfe6dYrOADtoujbiDM5mvGf8ZQ2SCXA4KQLBsIy4A>
<xmx:VBuQZCIZzE6RraVNzHNJ3cdnRd_A8EPQ4MIKc6T8cIK-c2vBCxWfew>
<xmx:VBuQZMzbuRPUkrDFfeHC9CQ4tL-9IG3c60ARNSKFAe3dVCxgadLCCA>
<xmx:VBuQZBlAClbV0hG7P8Jyi-YScf5zT5YRDQVvTOzCgU3d7H-UxbqOQg>
Feedback-ID: i8e5b41ae:Fastmail
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Content-Language: nl, en-US
In-Reply-To: <CAC-uhUB0mq2LmJRGwHtcZ09A1WntBPP9+FcB+D9dqQqmPK6XLQ@mail.gmail.com>
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: <283236db-95a3-f4cd-cf98-87792b369e52@roelschroeven.net>
X-Mailman-Original-References: <CAC-uhUB0mq2LmJRGwHtcZ09A1WntBPP9+FcB+D9dqQqmPK6XLQ@mail.gmail.com>
 by: Roel Schroeven - Mon, 19 Jun 2023 09:09 UTC

Op 19/06/2023 om 10:43 schreef Peter Slížik via Python-list:
> Hello,
>
> what is the preferred way of annotating file system paths?
>
> This StackOverflow answer <https://stackoverflow.com/a/58541858/1062139>
> (and a few others) recommend using the
>
> str | os.PathLike
>
> union.
>
> However, byte arrays can be used as paths too, and including them
> would make the annotation quite long.
You don't have to type out the whole thing every time. Define it somewhere:

PathLike = str | bytes | os.PathLike

and then you can use PathLike everywhere.
> I also believe that str confirms to the PathLike definition. Please,
> correct me if I'm wrong.
I don't think so: os.PathLike instances must have a __fspath__() method,
which str and bytes don't have.
> And finally - using paths in Python programs is so common, that one
> would expect to have a special type (or type alias) in typing. Am I
> missing something?
I agree there should be something like that. This StackOverflow answer
(https://stackoverflow.com/a/68027757/59122) talks about something like
that: _typeshed.AnyPath. It is used in the standard library, but
apparently it doesn't exist at runtime and you need a trick to make it
work. I would expect something better to exist, but as far as I can find
out there isn't.

PEP 519 has a little section on the topic
(https://peps.python.org/pep-0519/#provide-specific-type-hinting-support):

> Provide specific type hinting support
>
> There was some consideration to providing a generic typing.PathLike
class which would allow for e.g. typing.PathLike[str] to specify a type
hint for a path object which returned a string representation.
> While potentially beneficial, the usefulness was deemed too small to
bother adding the type hint class.
>
> This also removed any desire to have a class in the typing module
which represented the union of all acceptable path-representing types as
that can be represented with typing.Union[str, bytes,
> os.PathLike] easily enough and the hope is users will slowly
gravitate to path objects only.

--

"This planet has - or rather had - a problem, which was this: most of the
people living on it were unhappy for pretty much of the time. Many solutions
were suggested for this problem, but most of these were largely concerned with
the movement of small green pieces of paper, which was odd because on the whole
it wasn't the small green pieces of paper that were unhappy."
-- Douglas Adams

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor