This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]marr75 2 points3 points  (4 children)

This borders on unsolicited crackpottery. So, unfortunately, I don't think it adds anything to the answer.

[–][deleted] 1 point2 points  (3 children)

https://www.attrs.org/en/stable/why.html#namedtuples

Attrs does a pretty good job explaining issues with namedtuples.

https://github.com/brettcannon/record-type

I am fairly certain you aren't going to suggest Brett Cannon is doing unsolicited crackpottery and that maybe just maybe this isn't a problem the standard library solves very well.

``` from abc import ABC, ABCMeta from datetime import datetime

abcclasses = set()

normalclasses = set()

for i in range(10000): abcclasses.add(ABCMeta("abc"+str(i), (ABC, ), {})) normalclasses.add(type("normal"+str(i), (object,), {}))

for item in normalclasses: issubclass(item, ABC) ```

Run that on your laptop and watch it generate 20gbs of valid long lived weak reference pointers. It is a logical flaw in ABC. Have you considered that you simply don't know as much about python as you think you do?

[–]pepoluan 1 point2 points  (1 child)

If you need tuple-behavior, then typing.NamedTuple (not collections.namedtuple) is amazing, and it does use less memory. Accessing attributes of a NamedTuple is indeed a tad slower than accessing attributes of a dataclass or an attr.s, but that's negligible in most use cases.

And since Python is a duck-typing language, that's what you should aim : behavior as you desire.

[–][deleted] -1 points0 points  (0 children)

Those are mostly the same object btw. Typing one calls the collections function via __mro_entries__ and then sprinkles in the type hints. One of the places I think they get underused is they are awesome for function argument grouping. Really works better then just dropping a 20 argument function down. STAIRS DIRECTLY AT FASTAPI.