Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def method(
self: "Env", name: str, default: typing.Any = ma.missing, subcast: typing.Type = None, **kwargs
):
if self._sealed:
raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
parsed_key, raw_value, proxied_key = self._get_from_environ(name, default)
if raw_value is ma.missing:
raise EnvError('Environment variable "{}" not set'.format(proxied_key or parsed_key))
value = func(raw_value, **kwargs)
self._fields[parsed_key] = ma.fields.Field(**kwargs)
self._values[parsed_key] = value
return value
def method(
self: "Env", name: str, default: typing.Any = ma.missing, subcast: Subcast = None, **kwargs
) -> _T:
if self._sealed:
raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
missing = kwargs.pop("missing", None) or default
if isinstance(field_or_factory, type) and issubclass(field_or_factory, ma.fields.Field):
field = field_or_factory(missing=missing, **kwargs)
else:
field = field_or_factory(subcast=subcast, missing=missing, **kwargs)
parsed_key, raw_value, proxied_key = self._get_from_environ(name, ma.missing)
self._fields[parsed_key] = field
source_key = proxied_key or parsed_key
if raw_value is ma.missing and field.missing is ma.missing:
message = "Environment variable not set."
if self.eager:
raise EnvValidationError('Environment variable "{}" not set'.format(source_key), [message])
else:
self._errors[parsed_key].append(message)
if raw_value or raw_value == "":
value = raw_value