Skip to content

Combining the functionality of nameof with jsobj? #110

@oliversheridanmethven

Description

@oliversheridanmethven

I have a wrapper this is nearly identical to the helper jsobj, but I noticed today it falls short in one regard, which is that it doesn't have the full power of nameof when it comes to getting the "full/base name" of the object that was put in.

What jsobj does:

a, b = 1, 2
jsobj(a, b) # {'a': 1, 'b': 2}

What nameof can do:

func.a.b = 1
nameof(func.a.b, vars_only=False) # 'func.a.b'

What I would like to have

a = 1
func.a.b = 2
some_function(a, func.a.b) # {'a': 1, 'func.a.b': 2}

Perhaps there could be a keyword keep_base argument added to jsobj along the lines of:

def jsobj(*args, keep_base=True, **kwargs): ...

I appreciate this would add a blind spot to the function.

Is something like this possible with the existing setup?

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