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

Support two-step method calls and allow retrieving built-in methods using getattr #8931

Closed
wants to merge 1 commit into from

Conversation

Quarz0
Copy link
Contributor

@Quarz0 Quarz0 commented Jul 18, 2019

Related: bazelbuild/starlark#20 (comment), #5224

It's now possible to call methods in two steps y = x.f; y()
Also, getattr can now be used to retrieve built-in methods.

using getattr.

It's now possible to call methods in two steps `y = x.f; y()`
@laurentlb
Copy link
Contributor

Assigning to @vladmos for review and import

fyi @alandonovan, this fixes a very long-standing issue

Copy link
Member

@vladmos vladmos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bazel-io bazel-io closed this in a7b2b11 Jul 24, 2019
bazel-io pushed a commit that referenced this pull request Dec 2, 2019
github.com//pull/8931 was an incomplete fix to b/21392896:
it allowed 'x.f()' to be expressed as 'y=x.f; y()' in most cases, but not all.
In particular, it did not address the to_json and to_proto methods of
structs (which we should get rid of, BTW). This change is an ad-hoc fix for
those two methods. A more principled fix will have to wait till an integrated
clean-up of Info/StructImpl/NativeInfo.

This change is a prerequisite for fixing github.com//issues/10339,
which is in turn a prerequisite for various simplifications and optimizations to
Starlark's function calling mechanism.

I audited Google's .bzl corpus for cases where the three-argument
getattr(x, name, dflt) was called with either an arbitrary name or
a name obtained from dir(x) without filtering, and where subsequent
operations might change their behavior if given a bound method instead
of 'dflt'. This turned up only two locations, both easily fixed (CL 283224061).

PiperOrigin-RevId: 283433923
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this pull request Sep 4, 2022
    github.com/bazelbuild/bazel/pull/8931 was an incomplete fix to b/21392896:
    it allowed 'x.f()' to be expressed as 'y=x.f; y()' in most cases, but not all.
    In particular, it did not address the to_json and to_proto methods of
    structs (which we should get rid of, BTW). This change is an ad-hoc fix for
    those two methods. A more principled fix will have to wait till an integrated
    clean-up of Info/StructImpl/NativeInfo.

    This change is a prerequisite for fixing github.com/bazelbuild/bazel/issues/10339,
    which is in turn a prerequisite for various simplifications and optimizations to
    Starlark's function calling mechanism.

    I audited Google's .bzl corpus for cases where the three-argument
    getattr(x, name, dflt) was called with either an arbitrary name or
    a name obtained from dir(x) without filtering, and where subsequent
    operations might change their behavior if given a bound method instead
    of 'dflt'. This turned up only two locations, both easily fixed (CL 283224061).

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

Successfully merging this pull request may close these issues.

5 participants