Skip to content

Can't print attr when attr name contains "\n" #122

@Withered-Flower-0422

Description

@Withered-Flower-0422

Edge case though, as shown in title, when an attr name contains "\n", this attr won't be printed.

from objprint import op
op.config(arg_name=True)

class A:
    def __init__(self):
        self.x = 41
        setattr(self, "\n", 42)

a = A()
for attr in dir(a):
    if not attr.startswith("_"):
        print(f"{attr}: {getattr(a, attr)}")
op(a)

Code above prints:

 // a blank line here
: 42
x: 41
a:
<A 0x23202c55d30
  .x = 41
>

a does have an attribute named "\n" whose value is 42, but op ignores it.

Actually regex made the mistake.

re.fullmatch(r"(?!_).*", '\n') # this returns None

Code in objprint.py wrote like above, mistakenly ignores those attr_names which contain "\n".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions