basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Don't flag conditional constant definitions (`reportConstantRedefinition`/`reportRedeclaration`)

Open RBerga06 opened this issue 3 months ago • 1 comments

Description

Apparently basedpyright does not support conditional constants (nor conditional class / type alias definitions). For example:

# pyright: reportUnreachable=false
import sys

class MacFoo: pass
class WinFoo: pass
class LinFoo: pass


if sys.platform == "darwin":
    OS = "macOS"
    type SysFoo = MacFoo  # reportRedeclaration
    class SysBar: pass    # reportRedeclaration

elif sys.platform == "win32":
    OS = "Windows"        # reportConstantRedefinition
    type SysFoo = WinFoo  # reportRedeclaration
    class SysBar: pass    # reportRedeclaration

else:
    OS = "Linux"          # reportConstantRedefinition
    type SysFoo = LinFoo
    class SysBar: pass

(basedpyright playground)

This issue also affects pyright (playground link), but this was considered expected behaviour (upstream issue: https://github.com/microsoft/pyright/issues/5265).

RBerga06 avatar Nov 27 '25 19:11 RBerga06

hmm i thought we had an issue for this already but i guess not. thanks

DetachHead avatar Nov 27 '25 23:11 DetachHead