pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

support multiple values for `python-platform`

Open DetachHead opened this issue 6 months ago • 5 comments

it's very common for python projects to be run on multiple platforms (especially if you're developing a library). python-platform should support specifying an array of values eg:

python-platform = ["linux", "win32"]

and maybe an "all" option as well, which both ty and pyright support

DetachHead avatar May 18 '26 03:05 DetachHead

Thanks for the request, @DetachHead! Verified pyrefly does NOT support this today, and there's actually a related footgun worth flagging.

Current state (confirmed against HEAD):

Config Result
python-platform = ["linux", "win32"] Rejected: invalid type: sequence, expected a string
python-platform = "all" Silently accepted as a custom unknown platform name
python-platform = "All" Silently aliased to "linux" (not multi-platform!)

The PythonPlatform config is a String newtype, single-value-only (crates/pyrefly_python/src/sys_info.rs:177). The constructor PythonPlatform::new normalizes "All" → linux for Pyright compatibility, but doesn't implement actual multi-platform semantics — so users who pass "All" thinking they're getting multi-platform coverage are silently only checking linux. That's a footgun worth fixing as part of this work.

Two-part fix:

  1. Config schema — accept python-platform: ["linux", "win32"] (array form) and have "all" / "All" mean the actual union of all known platforms (not silently aliased to linux).
  2. Type-check propagation — wherever pyrefly currently uses the configured platform to gate symbol availability or narrow sys.platform, it needs to consider the union of configured platforms. A symbol should be treated as available if it exists on any configured platform; sys.platformnarrowed branches under multi-platform mode shouldn't narrow to a single concrete value.

Both ty and pyright already support this pattern. Adopting the same shape would help migration.

Tagging @connernilsen for routing (config surface).

NathanTempest avatar May 19 '26 16:05 NathanTempest

Hey @DetachHead, thanks for submitting this issue. I've been thinking about this while reading your post, and I think it's a reasonable thing to add. I'll open it up to external contribution.

connernilsen avatar May 19 '26 16:05 connernilsen

Picking this up to see if I can land a solution to this problem.

NathanTempest avatar May 19 '26 17:05 NathanTempest

@asukaminato0721 thank you for putting out the PR, I will unassign myself.

NathanTempest avatar May 19 '26 17:05 NathanTempest

claim

asukaminato0721 avatar Jun 23 '26 03:06 asukaminato0721