hf-hub
hf-hub copied to clipboard
chore: `ApiBuilder` should support `Default` without a token
When creating an API instance the current methods enforce checking for a local token
file, even when you intend to provide your own via with_token()
, thus finding a token is redundant, as is the info log of one missing being emitted.
-
from_cache()
callscache.token()
to set thetoken
field in the builder. - You cannot call
with_token()
prior, bothdefault()
andnew()
methods use the same initialization. Only workaround is to duplicatefrom_cache()
and omit the token check. - The token is later used by the private
build_headers()
method during the finalbuild()
call.
This PR changes:
- The
Default
impl for both sync/async structs to provide the same struct value except for thetoken
field, leaving it asNone
by default.from_cache()
will use the "Struct Update" syntax to spread the remaining default field values (this communicates more clearly what the method is actually modifying). - The order of fields for the
Api
andApiBuilder
structs were grouped contextually for better visibility vs interleaved. Handled via a separate commit.
I've tried to minimize affecting anything else, but technically if someone was relying on ApiBuilder::default()
before instead of ::new()
, the only difference should be that token
is not potentially set for them. Anyone who is using ::new()
should be unaffected by this change.
Related: https://github.com/huggingface/hf-hub/issues/54#issuecomment-2118679106