Skip to content

Make NamedTuple attributes read-only - #5299

Merged
emmatyping merged 1 commit into
python:masterfrom
emmatyping:ntmutprotocol
Jun 29, 2018
Merged

emmatyping merged 1 commit into
python:masterfrom
emmatyping:ntmutprotocol

Conversation

@emmatyping

Copy link
Copy Markdown
Member

It seems namedtuples are covered already, but typing.NamedTuples are not. This fixes #5293 .

@emmatyping
emmatyping requested a review from ilevkivskyi June 29, 2018 17:12

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@gvanrossum

gvanrossum commented Jun 29, 2018 •

Copy link
Copy Markdown
Member

Can you add a test to make sure that if the variable is a property not because it's a NamedTuple and if the property defines a setter, this won't incorrectly reject setting such a property?

@property
def foo(self): ...
@foo.setter
def foo(self, value): ...

@ilevkivskyi

Copy link
Copy Markdown
Member

There is already such a test testSettablePropertyInProtocols (but I am, unlike @JukkaL, totally fine with adding more tests).

@emmatyping

Copy link
Copy Markdown
Member Author

I'm not sure if I can write a test that wouldn't exactly duplicate the functionality of testSettablePropertyInProtocols or testPropertyWithSetter... but if you have a suggestion I am more than happy to hear it.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, never mind then. Let's go with this!

@emmatyping
emmatyping merged commit 028bd91 into python:master Jun 29, 2018
@emmatyping
emmatyping deleted the ntmutprotocol branch January 31, 2019 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NamedTuple should not satisfy Protocol with mutable fields

3 participants