On 10/17/2019 2:36 PM, Steve Jorgensen wrote:
Andrew Barnert wrote:
[snip]
But meanwhile, you still haven’t given any reason why Record would be useful. 
What
exactly is it supposed to mean? When would you want to check it? What would you 
do with an
object only if you know it’s a Record?
This isn’t like checking for a POD type in C++ or a struct type in Swift, 
because none
of the important things that tells you even make sense in Python.

The reason I am interested in having it is to disambiguate collections that are 
primarily to be treated as collections of values from those that are primarily 
to be accessed as attributes with values. As an example, when converting to 
JSON, it would make more sense to represent a regular tuple as a JSON array, 
but it would make more sense to represent a namedtuple as a JSON object.

This seems specific to your application. I don't think the language can disambiguate this for you. I think the best you can do is use the known way of looking for namedtuples and dataclasses. Although I think that in dataclasses case, is_dataclass is an anti-pattern and I should not have added it.

For your use case, what's the difference between these two classes:

@dataclass
class A:
    x: int
    y: float

class B:
    def __init__(self, x, y):
        self.x = x
        self.y = y

Do you really want code that treats these differently, just because one used some shortcut to write the __init__ function?

Eric
_______________________________________________
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/FS5HJGQS6W3RZSHHQI5EP4R3PB7IA5IV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to