buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

prelude: Python is typechecked as 3.10 by default

Open 9999years opened this issue 6 months ago • 0 comments

When calling python_library or python_binary, a [typecheck] subtarget is created. However, unless you also add an explicit py_version_for_type_checking argument, the typechecker assumes the sources are for Python 3.10, not the version attribute of the Python toolchain being used.

Source code references

https://github.com/facebook/buck2/blob/985f5d89915af45353c2daa3df018bb967893cfa/prelude/python/typing.bzl#L17

Here, DEFAULT_PY_VERSION is passed to the typechecker unless py_version is set: https://github.com/facebook/buck2/blob/985f5d89915af45353c2daa3df018bb967893cfa/prelude/python/typing.bzl#L47

Here, py_version_for_type_checking is passed to the typechecker, not using python_toolchain.version as an alternate value: https://github.com/facebook/buck2/blob/985f5d89915af45353c2daa3df018bb967893cfa/prelude/python/python_library.bzl#L414

Here, py_version_for_type_checking is defined with a default of None (which turns into "3.10"): https://github.com/facebook/buck2/blob/985f5d89915af45353c2daa3df018bb967893cfa/prelude/decls/python_rules.bzl#L143-L145

9999years avatar Jul 11 '25 23:07 9999years