Skip to content

Commit

Permalink
Set fiddle_type_name for PaxConfig and PaxPartial to Config and Partial.
Browse files Browse the repository at this point in the history
This ensures that `PaxConfig` matches `Config` in the matcher.

Also remove the `use-pax-fiddle-overlay` flag; we do want to enable
`pax-fiddle` everywhere `fiddle` is enabled.

PiperOrigin-RevId: 583116861
  • Loading branch information
martindemello authored and rchen152 committed Nov 16, 2023
1 parent 7e06f71 commit b9e15c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 0 additions & 2 deletions pytype/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ def add_options(o, arglist):
"Variables initialized as None retain their None binding."),
_flag("--use-fiddle-overlay", False,
"Support the third-party fiddle library."),
_flag("--use-pax-fiddle-overlay", False,
"Support the third-party pax_fiddle library."),
] + _OPT_IN_FEATURES


Expand Down
21 changes: 18 additions & 3 deletions pytype/overlays/fiddle_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
_INSTANCE_CACHE: Dict[Tuple[Node, abstract.Class, str], abstract.Instance] = {}


_CLASS_ALIASES = {
"Config": "Config",
"PaxConfig": "Config",
"Partial": "Partial",
"PaxPartial": "Partial"
}


class FiddleOverlay(overlay.Overlay):
"""A custom overlay for the 'fiddle' module."""

Expand Down Expand Up @@ -61,7 +69,7 @@ def __init__(self, name, ctx, module):
mixin.HasSlots.init_mixin(self)
self.set_native_slot("__getitem__", self.getitem_slot)
# For consistency with the rest of the overlay
self.fiddle_type_name = name
self.fiddle_type_name = _CLASS_ALIASES[name]
self.module = module

def __repr__(self):
Expand Down Expand Up @@ -150,7 +158,9 @@ def getitem_slot(self, node, index_var) -> Tuple[Node, abstract.Instance]:
"""Specialize the generic class with the value of index_var."""

underlying = index_var.data[0]
ret = BuildableType(self.name, underlying, self.ctx, module=self.module)
ret = BuildableType(
self.fiddle_type_name, underlying, self.ctx, module=self.module
)
return node, ret.to_variable(node)

def get_own_new(self, node, value) -> Tuple[Node, Variable]:
Expand All @@ -177,12 +187,16 @@ def __init__(
super().__init__(base_cls, formal_type_parameters, ctx, template) # pytype: disable=wrong-arg-types
self.fiddle_type_name = fiddle_type_name
self.underlying = underlying
self.module = module

def replace(self, inner_types):
inner_types = dict(inner_types)
new_underlying = inner_types[abstract_utils.T]
typ = self.__class__
return typ(self.fiddle_type_name, new_underlying, self.ctx, self.template)
return typ(
self.fiddle_type_name, new_underlying, self.ctx, self.template,
self.module
)

def instantiate(self, node, container=None):
_, ret = make_instance(
Expand Down Expand Up @@ -244,6 +258,7 @@ def make_instance(
) -> Tuple[Node, abstract.BaseValue]:
"""Generate a Buildable instance from an underlying template class."""

subclass_name = _CLASS_ALIASES[subclass_name]
if subclass_name not in ("Config", "Partial"):
raise ValueError(f"Unexpected instance class: {subclass_name}")

Expand Down
1 change: 0 additions & 1 deletion pytype/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def setUp(self):
strict_none_binding=True,
use_enum_overlay=True,
use_fiddle_overlay=True,
use_pax_fiddle_overlay=True,
validate_version=False,
)

Expand Down

0 comments on commit b9e15c9

Please sign in to comment.