Skip to content

Commit

Permalink
Remove no-longer-necessary __getattribute__s from enum.pytd.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 589254698
  • Loading branch information
rchen152 committed Dec 14, 2023
1 parent 39ad691 commit 8687370
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
16 changes: 3 additions & 13 deletions pytype/overlays/enum_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import collections
import contextlib
import logging
from typing import Any, Dict, Optional, Union
from typing import Optional, Union

from pytype.abstract import abstract
from pytype.abstract import abstract_utils
Expand Down Expand Up @@ -65,17 +65,7 @@ def __init__(self, ctx):
super().__init__(ctx, "enum", member_map, ctx.loader.import_name("enum"))


class _DelGetAttributeMixin:

_member_map: Dict[str, Any]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if "__getattribute__" in self._member_map:
del self._member_map["__getattribute__"]


class EnumBuilder(_DelGetAttributeMixin, abstract.PyTDClass):
class EnumBuilder(abstract.PyTDClass):
"""Overlays enum.Enum."""

def __init__(self, name, ctx, module):
Expand Down Expand Up @@ -288,7 +278,7 @@ def call(self, node, func, args, alias_map=None):
return node, self.ctx.convert.build_bool(node, this.cls == other.cls)


class EnumMeta(_DelGetAttributeMixin, abstract.PyTDClass):
class EnumMeta(abstract.PyTDClass):
"""Wrapper for enum.EnumMeta.
EnumMeta is essentially a container for the functions that drive a lot of the
Expand Down
9 changes: 0 additions & 9 deletions pytype/stubs/stdlib/enum.pytd
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# TODO(tsudol): Improve enum support so the `__getattribute__`s can be removed:
# - Remove EnumMeta.__getattribute__
# - Remove Enum.__getattribute__
# - Remove auto.__getattribute__
# The enum overlay removes __getattribute__ from EnumMeta and Enum when enabled.

from typing import Any, Dict, Iterable, Iterator, Tuple, Type, TypeVar, Union

_T = TypeVar('_T')
_EnumType = TypeVar('_EnumType', bound=Type[Enum])

class EnumMeta(type, Iterable):
def __getattribute__(self, name) -> Any: ...
def __iter__(self: Type[_T]) -> Iterator[_T]: ...
def __getitem__(cls: EnumMeta, name: str) -> Any: ...
def __contains__(self, member: Enum) -> bool: ...
Expand All @@ -29,7 +22,6 @@ class Enum(metaclass=EnumMeta):
def __eq__(self, other: Any) -> bool: ...
def __new__(cls, value: str, names: Union[str, Iterable[str], Iterable[Tuple[str, Any]], Dict[str, Any]], module = ..., type: type = ..., start: complex = ...) -> Type[Enum]: ...
def __new__(cls: Type[_T], value) -> _T: ...
def __getattribute__(self, name) -> Any: ...

class IntEnum(int, Enum): ...

Expand All @@ -40,7 +32,6 @@ _auto_null: Any
class auto:
value: Any
def __init__(self) -> None: ...
def __getattribute__(self, name) -> Any: ...
def __or__(self: _T, other: _T) -> _T: ...
def __and__(self: _T, other: _T) -> _T: ...
def __xor__(self: _T, other: _T) -> _T: ...
Expand Down

0 comments on commit 8687370

Please sign in to comment.