[Python-ideas] Re: Idea: Tagged strings in python
collections.UserString can take away a lot of this boilerplate pain from user defined str subclasses. On Sun, Dec 18, 2022 at 7:28 PM Steven D'Aprano wrote: > On Sun, Dec 18, 2022 at 07:38:06PM -0500, David Mertz, Ph.D. wrote: > > > However, if you want to allow these types to possibly *do* something with > > the strings inside (validate them, canonicalize them, do a security > check, > > etc), I think I like the other way: > > > > #2 > > > > class html(str): pass > > class css(str): pass > > The problem with this is that the builtins are positively hostile to > subclassing. The issue is demonstrated with this toy example: > > class mystr(str): > def method(self): > return 1234 > > s = mystr("hello") > print(s.method()) # This is fine. > print(s.upper().method()) # This is not. > > > To be useable, we have to override every string method that returns a > string. Including dunders. So your class becomes full of tedious boiler > plate: > > def upper(self): > return type(self)(super().upper()) > def lower(self): > return type(self)(super().lower()) > def casefold(self): > return type(self)(super().casefold()) > # Plus another 29 or so methods > > This is not just tedious and error-prone, but it is inefficient: calling > super returns a regular string, which then has to be copied as a > subclassed string and the original garbage collected. > > > -- > Steve > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/O7PU5FLLGNR7IR2V667LDPBBOEXF5NFU/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4RIQ65SHYK3T2KZ2XKOPD45KH2SOFQFI/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Requirements.txt inside virtual environment
`pip freeze` can be useful for this kind of thing On Thu, 17 Feb 2022 at 18:19, Chris Angelico wrote: > On Fri, 18 Feb 2022 at 13:12, Vishesh Mangla > wrote: > > > > Consider the following scenario: > > 1) You have to format your pc. > > 2) You copy your python projects to your hard disk along with the > virtual environment(I keep the virtual environment in the project folder > only). > > 3)When you copy your projects back after successfully formatting your > pc, the useless virtualenv lies there and you can't get the > requirements.txt now and have to install all packages one by one. > > > > It could be great if pip or python or anyone would by default store a > requirements.txt file inside the virtual env and on `pip install xyz` > would append `xyz` to that file. > > > > OR! You maintain your own requirements.txt manually, and always use > 'pip install -r requirements.txt' when you change it. That works much > better with source control. > > ChrisA > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/YNU3D2FH6L75DLHTQS4A7Q7EV6UVYOCM/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VRVU3OL2RY6TXKKXKYG2NYTZXYZVOI5O/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Consider having numbers.Real provide __complex__?
Yes, I believe the ask is for `int.__complex__`, `float.__complex__` and `complex.__complex__` ( https://github.com/python/mypy/issues/3186#issuecomment-762121456) On Mon, 18 Jan 2021 at 09:47, Mark Dickinson wrote: > Inheriting from `numbers.Real` _does_ give you `__complex__`, though: > https://github.com/python/cpython/blob/314b8787e0c50985ba708034b84ff5b37a1d47de/Lib/numbers.py#L245-L248 > > Is it instead `float.__complex__` you're asking for? > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/L7KA5VUCJB77MUOXQPMMCSA3CDCM767O/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IG3UOCZFCCJTNOHWNQXRDSTWUNSVBZX2/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: unix filter, one liners, awk
Here's my take on a Python one liner tool: https://github.com/hauntsaninja/pyp It handles automatic intelligent printing, importing and more. It explicitly aims to feel very much like writing Python, as opposed to a DSL. In fact, it can even generate a runnable Python script to show you exactly what it's doing. README includes comparisons to Pyped, xonsh and others — there's a long history of people wanting more Python in their terminal :-) On Thu, 5 Nov 2020 at 23:35, Mike Müller wrote: > Am 06.11.20 um 08:15 schrieb Stephen J. Turnbull: > > Alex Hall writes: > > > > > Try https://github.com/ksamuel/Pyped > > > > Or perhaps https://xon.sh, and have Python be the native syntax of the > > shell. (Unfortunately if I read correctly xonsh is based on Python > > 3.5, so no walrus operator and no f-strings yet.) > > It says 3.5+. xonsh happily works with Python 3.9. ;) > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/WCIOPGNGYPHEIHVBQ7M6TZHI4UESTQSF/ > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6TEU33BBWOOUW2DZUY5EJRXAILI2P7L4/ Code of Conduct: http://python.org/psf/codeofconduct/