NamedTuple/dataclass special attribute __name__ incorrectly treated as immutable for matching protocols #8829
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
Describe the bug
When matching a
Protocol
with mutable special (class) attribute__name__
, aNamedTuple
/dataclass
class is rejected as immutable even though the (class) attribute is actually writeable. This seems to only affect__name__
; the__module__
and__qualname__
attributes are considered r/w.This seems to only trigger when matching against a
Protocol
. When directly working with the class attribute (e.g.my_tup.__name__ = "something"
), PyRight does not complain.Code or Screenshots
Consider a decorator that patches the name of classes. With recent PyRight versions, this only works for regular classes, not
NamedTuple
/dataclass
classes.Notably, there are no runtime errors. The
__name__
attribute is writeable on bothBrokenT
andBrokenD
at runtime.VS Code extension or command-line
Tested with the
python -m pyright
CLI on versionpyright 1.1.377
. Testing this in the PyRight Playground, the code was accepted up to PyRight 1.1.375.The text was updated successfully, but these errors were encountered: