Skip to content

Commit

Permalink
options: require passing hash to the Optioney
Browse files Browse the repository at this point in the history
It's now intended that the `factory()` method will be used when not
using `from_string`, so there's no reason to make it convenient to use
the main initializer, and passing the hash in is convenient for the
factory method.
  • Loading branch information
dcbaker committed Feb 12, 2025
1 parent ca94cf7 commit c7ec44e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ class OptionKey:
_hash: int
_as_tuple: T.Tuple[str, MachineChoice, str]

def __init__(self, name: str, subproject: str = '',
machine: MachineChoice = MachineChoice.HOST,
hash_: T.Optional[int] = None):
def __init__(self, name: str, subproject: str,
machine: MachineChoice, hash_: int):
# the _type option to the constructor is kinda private. We want to be
# able to save the state and avoid the lookup function when
# pickling/unpickling, but we need to be able to calculate it when
# constructing a new OptionKey
object.__setattr__(self, 'name', name)
object.__setattr__(self, 'subproject', subproject)
object.__setattr__(self, 'machine', machine)
object.__setattr__(self, '_hash', hash_ if hash_ is not None else hash((name, subproject, machine)))
object.__setattr__(self, '_hash', hash_)
object.__setattr__(self, '_as_tuple', (self.subproject, self.machine, self.name))

def __setattr__(self, key: str, value: T.Any) -> None:
Expand All @@ -138,6 +137,7 @@ def __getstate__(self) -> T.Dict[str, T.Any]:
'name': self.name,
'subproject': self.subproject,
'machine': self.machine,
'hash_': self._hash,
}

def __setstate__(self, state: T.Dict[str, T.Any]) -> None:
Expand Down Expand Up @@ -241,7 +241,7 @@ def from_string(cls, raw: str) -> 'OptionKey':
assert ':' not in opt
assert opt.count('.') < 2

return cls(opt, subproject, for_machine)
return cls.factory(opt, subproject, for_machine)

def evolve(self, name: T.Optional[str] = None, subproject: T.Optional[str] = None,
machine: T.Optional[MachineChoice] = None) -> 'OptionKey':
Expand Down

0 comments on commit c7ec44e

Please sign in to comment.