Skip to content

Commit

Permalink
Add a test case showing we can shadow builtins.pyi
Browse files Browse the repository at this point in the history
Summary:
We discovered recently that a user's buck target can accidentally
shadow builtin stubs, because user modules always take priority and
users can set `base_module = ''` with an `__init__.py`.

In general this behavior of allowing user files to shadow stdlib isn't
so bad - as a rule they won't, and it allows users to define a custom
typeshed. But for `builtins.pyi` sepecifically this is especially confusing
because the errors are extremely widespread and it's pretty hard to guess
what is happening since the empty qualifier is special.

So, to prevent a repeat of the debugging session we had we want to special-case
that `builtins.pyi` cannot be shadowed.

This commit adds a new test illustrating the issue, the next commit will cut
Pyre over to preferring `builtins.py`

Reviewed By: rchen152

Differential Revision: D65076555

fbshipit-source-id: c9b6138a2724b5eae4eec2836bd3707d7d517519
  • Loading branch information
stroxler authored and facebook-github-bot committed Oct 29, 2024
1 parent 6e63d8e commit 4800c02
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/buck_command/test/sourceCodeApiTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ let test_source_code_api =
assert_module_tracked ~context ~api !"a.d.e" ~expected:true;
assert_module_tracked ~context ~api !"a.x" ~expected:false;
());
(Test.labeled_test_case Stdlib.__FUNCTION__ Stdlib.__LINE__ ~name:"do not shadow builtins.pyi"
@@ fun context ->
let api =
let loader = FileLoader.create_for_testing ["__init__.py", ""; "builtins.pyi", ""] in
let listing =
Sourcedb.Listing.create_for_testing
~sources:["__init__.py"]
~dependencies:["builtins.pyi"]
()
in
create loader listing
in
assert_lookup_relative_path ~context ~api [!"", Some "__init__.py"];
());
]


Expand Down

0 comments on commit 4800c02

Please sign in to comment.