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 type fullname to AnalyzeTypeContext #6503

Closed
mkurnikov opened this issue Mar 1, 2019 · 2 comments
Closed

Add type fullname to AnalyzeTypeContext #6503

mkurnikov opened this issue Mar 1, 2019 · 2 comments

Comments

@mkurnikov
Copy link
Contributor

mkurnikov commented Mar 1, 2019

In the hooks returned from

    def get_type_analyze_hook(self, fullname: str
                              ) -> Optional[Callable[[AnalyzeTypeContext], Type]]: pass

user needs to create Instance objects in the hook, so fullname required there, but UnboundType does not have it.

Surely, user can make a callable factory and initialize it wil a fullname, but it would be so much easier just to get it from context object.

@ilevkivskyi
Copy link
Member

"make a callable factory and initialize it with a fullname" is literally one line:

from functools import partial

def get_type_analyze_hook(fullname):
    if interesting_name(fullname):
        return partial(my_hook, fullname)
    return None

def my_hook(fullname, ctx):
    # you have fullname here
    ...

Do we really need to add this field to the context (then why not to all contexts) if one can get it (if necessary) with a single line? After all Python is not Java.

@mkurnikov
Copy link
Contributor Author

Yes, you're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants