laike9m / pdir2

Pretty dir() printing with joy:beer:
MIT License
1.33k stars 47 forks source link

KeyError when formatting certain CATEGORIES #60

Closed iamgodot closed 2 years ago

iamgodot commented 2 years ago

Bug case

Currently the _FORMATTER in format.py misses three categories defined in AttrCategory enums, which will easily break the code during formatting, for instance:

import pdir
from collections import namedtuple

Person = namedtuple('Person', 'name age')
pdir(Person)

The direct cause comes from one of Person.__class_getitem__, which falls into category TYPING, tand he other two missing categories are SLOT and PATTERN_MATCHING.

Fix proposal

One easy way would be add a default formatter when getting from _FORMATTER. On the other hand, this _FORMATTER dict seems a bit redundant, so do the ATTR_MAP in attr_category.py(IMHO).

laike9m commented 2 years ago

Thanks for the bug report. Looks like you already have an idea on the fix, interested in creating a PR? I'll happily review it.

iamgodot commented 2 years ago

Thanks for the bug report. Looks like you already have an idea on the fix, interested in creating a PR? I'll happily review it.

Sure, it's here, please let me know if I need to change anything :)

iamgodot commented 2 years ago

Great, I'll close this now.