You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a function is annotated as 'pure', then it's checked that it doesn't operate against global state. ie, always returns inputs based only on arguments passed to it, and it doesn't do IO.
Also, functions annotated as 'pure' can only call other functions annotated as 'pure'
Reacted by Mauricio Scheffer, Carl Davidson, pawel-swiecki-saucelabs, Phillip Schanely, Andrew, Mike McDermott, Frederico Messa, Mateen Ulhaq and Armen Michaeli
It looks like it is possible to implement this in mypy (although not an easy task due to many implicit calls in Python, like __iter__() is called by for cycles). The problematic part is updating all the typeshed stubs marking all pure functions as @pure (hundreds files), otherwise such decorator will be quite useless.
The (eventual) implementation would probably work similar to "Any". ie, "purity of function is not known". You'd turn on a "strict" option to enable those warnings.
(same deal with most of typeshed, it's using an implicit Any in a huge amount of places, until pull requests come along which fix those).
The distinction you're mentioning there is described in the D wiki article, as being the difference between "pure" and "strong pure".
With just "pure", functions can modify their arguments (eg: self, for things like __iter__).
Functions that are annotated with both "pure" and only accept "Const" args or return a "Const" result, would be closer to "strong pure".
On Jan 14, 2018 2:37 AM, "wizzardx" ***@***.***> wrote:
The (eventual) implementation would probably work similar to "Any". ie,
"purity of function is not known". You'd turn on a "strict" option to
enable those warnings.
(same deal with most of typeshed, it's using an implicit Any in a huge
amount of places, until pull requests come along which fix those).
The distinction you're mentioning there is described in the D wiki
article, as being the difference between "pure" and "strong pure".
With just "pure", functions can modify their arguments (eg: self, for
things like *iter*), or other vars (not covered by "Const", which is in
separate issue/milestone).
Functions that are annotated with both "pure" and only accept "Const" args
or return a "Const" result, would be closer to "strong pure".
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4468 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACwrMuO3Xm3DborHpID1uGF6AO8uZfX2ks5tKdj5gaJpZM4RdhZN>
.
I'm not excited, but then again I've not had time to read those docs. But unless you've implemented such a system yourself for a real language I'd suggest that perhaps you have no idea how much work it would be for mypy. If you have implemented such a thing before, I recommend that you have a look at the mypy source code and think about how hard it would be to add it there. You'd also have to come up with a detailed design for how to write this without changing Python's core syntax. If you're not interested in doing this, feel free to close the issue now -- nobody on the mypy team has the time either.
Reacted by Joscha Götzer, pawel-swiecki-saucelabs, Sergi Simón Balcells, Arshia, Iliia Maleki and Frederico Messa
Activity
ilevkivskyi commentedon Jan 14, 2018
It looks like it is possible to implement this in mypy (although not an easy task due to many implicit calls in Python, like
__iter__()is called byforcycles). The problematic part is updating all the typeshed stubs marking all pure functions as@pure(hundreds files), otherwise such decorator will be quite useless.Therefore I think this is very low priority.
wizzardx commentedon Jan 14, 2018
The (eventual) implementation would probably work similar to "Any". ie, "purity of function is not known". You'd turn on a "strict" option to enable those warnings.
(same deal with most of typeshed, it's using an implicit Any in a huge amount of places, until pull requests come along which fix those).
The distinction you're mentioning there is described in the D wiki article, as being the difference between "pure" and "strong pure".
With just "pure", functions can modify their arguments (eg: self, for things like
__iter__).Functions that are annotated with both "pure" and only accept "Const" args or return a "Const" result, would be closer to "strong pure".
gvanrossum commentedon Jan 15, 2018
wizzardx commentedon Jan 16, 2018
One system that generalises these: effect systems.
Some details of how it's handled in Nim:
https://nim-lang.org/docs/manual.html#effect-system
Is that perhaps worthwhile to add to mypy, or also too complicated?
gvanrossum commentedon Jan 16, 2018
I'm not excited, but then again I've not had time to read those docs. But unless you've implemented such a system yourself for a real language I'd suggest that perhaps you have no idea how much work it would be for mypy. If you have implemented such a thing before, I recommend that you have a look at the mypy source code and think about how hard it would be to add it there. You'd also have to come up with a detailed design for how to write this without changing Python's core syntax. If you're not interested in doing this, feel free to close the issue now -- nobody on the mypy team has the time either.