[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Stephen J. Turnbull
Brian McCall writes: Steven d'Aprano writes: > > you have shown nothing to justify why unit support must be built > > into the language itself. > > I did what I could, but I'm not going to try and justify any more. That makes me sad, because everybody in the thread acknowledges that imp

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[David Mertz] >> Because the module implements >> http://speleotrove.com/decimal/decarith.html >> [Greg Ewing] > Well, yes, but someone made the decision to implement that > particular standard rather than one of the ones with fixed > precision. I'm a

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Brian McCall
> What does it *really* matter which of these you write? > that's just arguing over the colour of the bikeshed. > you have shown nothing to justify why unit support must be built into the > language itself. I did what I could, but I'm not going to try and justify any more. At the end of the da

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Steven D'Aprano
On Wed, Apr 06, 2022 at 03:50:35PM -, Brian McCall wrote: > Stephen J Turnbull and Paul Moore have asked why the "need" for > something other than a library (or perhaps a better library). There > are a number of examples that show simple unit calculations and it's > easy to argue based on t

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[Greg Ewing ] > So can you elaborate on how you use variable precision? Numeric programmers frequently want this. An extreme example is in function `collision_stats()` in your Python distribution's Lib/test/support/__init__.py. This needs to compute the variance of a distribution for which we only

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Greg Ewing
On 8/04/22 6:01 am, David Mertz, Ph.D. wrote: Because the module implements http://speleotrove.com/decimal/decarith.html Well, yes, but someone made the decision to implement that particular standard rather than one of the ones with fixed precisio

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Greg Ewing
On 8/04/22 5:15 am, Christopher Barker wrote: I actually have almost the opposite position -- variable precision is the most useful part of the Decimal type ;-) So can you elaborate on how you use variable precision? Note the docs again: "End users typically would not expect 1.1 + 2.2 to disp

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Steven D'Aprano
On Wed, Apr 06, 2022 at 11:48:44PM -0700, Ken Kundert wrote: > Perhaps a better approach would simply be to build > a units aware scientific calculator application. The Python REPL makes an awesome interactive calculator. Sagemath has done what you suggest: it is a powerful symbolic maths calc

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
On 07.04.2022 20:55, David Mertz, Ph.D. wrote: > On Thu, Apr 7, 2022 at 2:47 PM Marc-Andre Lemburg > wrote: > > In high finance, I've never seen decimals being used, only floats. > Excel is omnipresent, sets the standards and uses IEEE 754 floats > as well (plu

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Steven D'Aprano
On Wed, Apr 06, 2022 at 08:36:35PM +0100, Paul Moore wrote: > > compactness isn't typically regarded as a significant > selling point for a proposal. I would word that differently. Compactness *alone* isn't typically regarded as a *compelling* selling point, and *excessive* compactness is regar

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Steven D'Aprano
On Wed, Apr 06, 2022 at 04:54:15PM -, Brian McCall wrote: > Oops, my examples have some other problems: > > > # λ = 550e-9nm > > should be > > > # λ = 550nm This is an excellent example of why unit tracking, or any other programming system, is not a panacea. No programming system in th

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Stephen J. Turnbull
Chris Angelico writes: > > It's very difficult to get *any* syntax change in. In particular, > > changing '_' from an identifier component to an operator for > > combining numeric literals would invalidate *tons* of code > > (including internationalization code that is the 0.4

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread David Mertz, Ph.D.
On Thu, Apr 7, 2022 at 2:47 PM Marc-Andre Lemburg wrote: > In high finance, I've never seen decimals being used, only floats. > Excel is omnipresent, sets the standards and uses IEEE 754 floats > as well (plus some black magic which sometimes helps, but often > makes things worse): > In forex, i

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread Stephen J. Turnbull
malmiteria writes: > to dive into conceptual ideas a bit more: I'm not sure why you assume that nobody knows this stuff, at least at the extremely high and fuzzy level of your discussion. Executive summary: I see a lot of theory in your posts, but it's very difficult to tie it to *my* practice

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
There's theory and math, and then there's reality. In reality, some accounting systems use decimals with fixed precision for certain aspects and apply predefined rounding (usually defined in the contracts between the counterparties or in accounting/tax regulations), while others use IEEE 754 doubl

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[Christopher Barker ] > So what does Decimal provide? Two things that you can't do with the built-in > (hardware) float: > > Variable precision > Control of rounding And a third: precisely defined results in base 10. You're thinking like an engineer, not an accountant ;-) Politicians don't know a

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread David Mertz, Ph.D.
Because the module implements http://speleotrove.com/decimal/decarith.html On Thu, Apr 7, 2022 at 2:03 AM Greg Ewing wrote: > On 7/04/22 9:53 am, Chris Angelico wrote: > > how else would you do variable-precision in the standard library? > > Maybe the mistake was in thinking that we need variabl

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread David Mertz, Ph.D.
On Thu, Apr 7, 2022 at 10:51 AM Stephen J. Turnbull < stephenjturnb...@gmail.com> wrote: > NOTE: The big problem I see with this is that I don't see any > practical way to use syntax for non-numeric types like ndarray. > The problem is that in, say, economics we use a lot of m x 2 >

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Chris Angelico
On Fri, 8 Apr 2022 at 03:16, Christopher Barker wrote: > I'm no accountant, but this strikes me as quite dangerous -- sure decimal > fractions are exact, but who says you are only doing decimal arithmetic? > Calculating interest, inflation, who knows what could easily introduce > non-exactly-re

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Chris Angelico
On Fri, 8 Apr 2022 at 00:48, Stephen J. Turnbull wrote: > 1. Syntax, aka language support (the original suggestion of > user-defined literals fits here because either the way numbers are > parsed or the way '_' is parsed would have to change). > > It's very difficult to get *any* synt

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Christopher Barker
On Wed, Apr 6, 2022 at 11:03 PM Greg Ewing wrote: > Maybe the mistake was in thinking that we need variable > precision at all. > I actually have almost the opposite position -- variable precision is the most useful part of the Decimal type ;-) Warning: rant ahead: skip to the end for the relev

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Christopher Barker
After reading this long thread, a few notes: [preface: I write this as someone whose entire career is based on doing computation with Python, and with systems where physical units are critical and complex, and who maintains a fair bit of my own custom unit-oriented code -- this is not hypothesis]

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread malmiteria
Antoine Rozo writes: > If the only feature you need from super is the proxy one, why don't you > code your own parent-proxy-type? I did : https://github.com/malmiteria/super-alternative-to-super/blob/master/parent.py This is irrelevant to the discussion we're having i think. Essentially, I'm arg

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread Stephen J. Turnbull
malmiteria writes: > Stephen J. Turnbull writes: > > One really plausible example is given in Raymond's piece: a later > > version of the same library refactors a "monolithic" class as a child > > of one or more "private" classes that are not intended to be exposed > > in the public API, but

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Stephen J. Turnbull
Brian McCall writes: > Stephen J Turnbull and Paul Moore have asked why the "need" for > something other than a library (or perhaps a better library). There > are a number of examples that show simple unit calculations and > it's easy to argue based on those that nothing further is needed. No

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread malmiteria
to dive into conceptual ideas a bit more: inheritance is usually what we do when we mean *is a* for exemple, a cat *is an* animal, so we would write it like that: ``` class Animal: pass class Cat(Animal): pass ``` I believe my gobelin exemple is a fair case of MI since we can definitely say half

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread Antoine Rozo
If the only feature you need from super is the proxy one, why don't you code your own parent-proxy-type? class parentproxy: def __init__(self, cls, obj): self.__thisclass__ = cls self.__self_class__ = type(obj) self.__self__ = obj def __getattr__(self, name):

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread malmiteria
Greg Ewing writes: > If I were teaching a newcomer about super, I wouldn't even tell them > that it *has* a class argument. So they wouldn't have any expectation > about targeting, because they wouldn't know about it. I would probably teach newcomers the argumentless form only too. That's all the

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
On 07.04.2022 02:41, Greg Ewing wrote: > On 6/04/22 8:58 pm, Mark Dickinson via Python-ideas wrote: >> I'd be curious to know what alternatives you see. When a user writes `x + y` >> with both `x` and `y` instances of `decimal.Decimal`, the decimal module >> needs >> to know what precision to comp

[Python-ideas] Re: mro and super don't feel so pythonic

2022-04-07 Thread Stephen J. Turnbull
Chris Angelico writes: > I'm curious when you would ever be subclassing something from another > library without knowing its hierarchy. When the class is a public API, no? I'm not sure why this isn't obvious, am I missing something? One really plausible example is given in Raymond's piece: a

[Python-ideas] Re: Native support for units [was: custom literals]

2022-04-07 Thread Paul Moore
On Thu, 7 Apr 2022 at 01:18, Brian McCall wrote: > >> Please can you explain this to me? I don't know what you mean by "get the >> final answer", nor do I know how astropy.units is relevant. Units seems to >> be a perfectly acceptable library without astropy, is that not the case? > > Am I mista