Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a utility function for getting filename info from code objects #29

Closed
berkerpeksag opened this issue May 17, 2015 · 6 comments
Closed
Milestone

Comments

@berkerpeksag
Copy link
Owner

I think it would be useful to have https://github.com/berkerpeksag/astor/blob/master/astor/misc.py#L185-190 as an helper in astor.

@pmaupin
Copy link
Collaborator

pmaupin commented May 17, 2015

Maybe something like

    def finfo(codeobj):
        """Returns the file and line number of a code object.
            If the code object has a __file__ attribute (e.g. if
            it is a module), then the returned line number will
            be 0
        """
        fname = getattr(codeobj, '__file__', None)
        linenum = 0
        if fname is None:
            func_code = codeobj.__code__
            fname = func_code.co_filename
            linenum = func_code.co_firstlineno
        fname = fname.replace('.pyc', '.py')
        return fname, linenum

@berkerpeksag
Copy link
Owner Author

Yep, looks good!

@pmaupin
Copy link
Collaborator

pmaupin commented May 17, 2015

I'll add it. I think I'll add a couple of things for anti8 as well.

Thanks,
Pat

@berkerpeksag
Copy link
Owner Author

Thanks! Can you also add documentation for the new function?

@pmaupin
Copy link
Collaborator

pmaupin commented May 17, 2015

I'll try to figure that out :)

@pmaupin pmaupin mentioned this issue May 17, 2015
@berkerpeksag berkerpeksag modified the milestone: 0.6 May 22, 2015
@pmaupin
Copy link
Collaborator

pmaupin commented May 24, 2015

Done in the code cleanup.

@pmaupin pmaupin closed this as completed May 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants