[Proposal] System.put_env/2 clears env on getting nil as value

31 views
Skip to first unread message

Michal Śledź

unread,
Sep 18, 2023, 12:41:23 PM9/18/23
to elixir-lang-core
System.put_env/1 erases given key when a value is nil.

The proposal is to make System.put_env/2 symmetric with the System.put_env/1 and also erase a key on the nil value.

The spec would change from:

@spec put_env(binary(), binary()) :: :ok

to:

@spec put_env(binary(), binary() | nil) :: :ok

José Valim

unread,
Sep 18, 2023, 12:54:12 PM9/18/23
to elixir-l...@googlegroups.com
Sounds good to me. PR welcome!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0cc7caf8-f152-4476-9472-454c5c7e2f07n%40googlegroups.com.

Michal Śledź

unread,
Sep 18, 2023, 1:38:36 PM9/18/23
to elixir-lang-core
I did the change and when updating tests I noticed there is already `delete_env` and now I am no longer sure about modyfing put_env. If we do it, we should probably deprecate delete_env? 

Wojtek Mach

unread,
Sep 18, 2023, 1:42:25 PM9/18/23
to elixir-l...@googlegroups.com
While rather uncommon to delete things by setting to nil, I think parity with put_env/1 is worth it. I think it is fine to have put_env and delete_env. delete_env matches Application.delete_env, {Map,Keyword}.delete, etc, so I’d definitely keep it.

Reply all
Reply to author
Forward
0 new messages