Skip to content

Measure should subclass Real itself #83

@yunruse

Description

@yunruse

A Measure cannot be turned into a Fraction easily:

>>> a = (lunation % day) / day
>>> a
0.53058912
>>> Fraction(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/fractions.py", line 140, in __new__
    raise TypeError("argument should be a string "
TypeError: argument should be a string or a Rational instance

We can see already that Measure is a Generic[T] where T is a Real. This could be extended; Measure should subclass the Real itself rather than holding it as its value.

This would vastly improve interoperability and also reduce the necessary methods added to keep Real compatibility (.imag, __int__ and so on).

Indeed it may be possible to later support the superclass Complex, though the methods dropped by this may cause some typing headaches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    typingRelated to strong-typing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions