style: prefer type() over __class__
This commit is contained in:
parent
fd0fd2c6d4
commit
517ba21d5e
@ -1157,7 +1157,7 @@ class App(MiddlewareMixin, LifespanMixin):
|
|||||||
if hasattr(handler_fn, "__name__"):
|
if hasattr(handler_fn, "__name__"):
|
||||||
_fn_name = handler_fn.__name__
|
_fn_name = handler_fn.__name__
|
||||||
else:
|
else:
|
||||||
_fn_name = handler_fn.__class__.__name__
|
_fn_name = type(handler_fn).__name__
|
||||||
|
|
||||||
if isinstance(handler_fn, functools.partial):
|
if isinstance(handler_fn, functools.partial):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -161,7 +161,7 @@ class ComponentNamespace(SimpleNamespace):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the namespace.
|
The hash of the namespace.
|
||||||
"""
|
"""
|
||||||
return hash(self.__class__.__name__)
|
return hash(type(self).__name__)
|
||||||
|
|
||||||
|
|
||||||
def evaluate_style_namespaces(style: ComponentStyle) -> dict:
|
def evaluate_style_namespaces(style: ComponentStyle) -> dict:
|
||||||
@ -2565,7 +2565,7 @@ class LiteralComponentVar(CachedVarOperation, LiteralVar, ComponentVar):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the var.
|
The hash of the var.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._js_expr))
|
return hash((type(self).__name__, self._js_expr))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
|
@ -49,9 +49,9 @@ class Cond(MemoizationLeaf):
|
|||||||
The conditional component.
|
The conditional component.
|
||||||
"""
|
"""
|
||||||
# Wrap everything in fragments.
|
# Wrap everything in fragments.
|
||||||
if comp1.__class__.__name__ != "Fragment":
|
if type(comp1).__name__ != "Fragment":
|
||||||
comp1 = Fragment.create(comp1)
|
comp1 = Fragment.create(comp1)
|
||||||
if comp2 is None or comp2.__class__.__name__ != "Fragment":
|
if comp2 is None or type(comp2).__name__ != "Fragment":
|
||||||
comp2 = Fragment.create(comp2) if comp2 else Fragment.create()
|
comp2 = Fragment.create(comp2) if comp2 else Fragment.create()
|
||||||
return Fragment.create(
|
return Fragment.create(
|
||||||
cls(
|
cls(
|
||||||
|
@ -139,9 +139,7 @@ class RadixThemesComponent(Component):
|
|||||||
component = super().create(*children, **props)
|
component = super().create(*children, **props)
|
||||||
if component.library is None:
|
if component.library is None:
|
||||||
component.library = RadixThemesComponent.__fields__["library"].default
|
component.library = RadixThemesComponent.__fields__["library"].default
|
||||||
component.alias = "RadixThemes" + (
|
component.alias = "RadixThemes" + (component.tag or type(component).__name__)
|
||||||
component.tag or component.__class__.__name__
|
|
||||||
)
|
|
||||||
# value = props.get("value")
|
# value = props.get("value")
|
||||||
# if value is not None and component.alias == "RadixThemesSelect.Root":
|
# if value is not None and component.alias == "RadixThemesSelect.Root":
|
||||||
# lv = LiteralVar.create(value)
|
# lv = LiteralVar.create(value)
|
||||||
|
@ -1556,7 +1556,7 @@ class LiteralEventVar(VarOperationCall, LiteralVar, EventVar):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the var.
|
The hash of the var.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._js_expr))
|
return hash((type(self).__name__, self._js_expr))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
@ -1620,7 +1620,7 @@ class LiteralEventChainVar(ArgsFunctionOperationBuilder, LiteralVar, EventChainV
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the var.
|
The hash of the var.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._js_expr))
|
return hash((type(self).__name__, self._js_expr))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
|
@ -438,7 +438,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
Returns:
|
Returns:
|
||||||
The string representation of the state.
|
The string representation of the state.
|
||||||
"""
|
"""
|
||||||
return f"{self.__class__.__name__}({self.dict()})"
|
return f"{type(self).__name__}({self.dict()})"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_computed_vars(cls) -> list[ComputedVar]:
|
def _get_computed_vars(cls) -> list[ComputedVar]:
|
||||||
@ -3618,7 +3618,7 @@ class MutableProxy(wrapt.ObjectProxy):
|
|||||||
Returns:
|
Returns:
|
||||||
The representation of the wrapped object.
|
The representation of the wrapped object.
|
||||||
"""
|
"""
|
||||||
return f"{self.__class__.__name__}({self.__wrapped__})"
|
return f"{type(self).__name__}({self.__wrapped__})"
|
||||||
|
|
||||||
def _mark_dirty(
|
def _mark_dirty(
|
||||||
self,
|
self,
|
||||||
|
@ -1569,7 +1569,7 @@ class CachedVarOperation:
|
|||||||
if name == "_js_expr":
|
if name == "_js_expr":
|
||||||
return self._cached_var_name
|
return self._cached_var_name
|
||||||
|
|
||||||
parent_classes = inspect.getmro(self.__class__)
|
parent_classes = inspect.getmro(type(self))
|
||||||
|
|
||||||
next_class = parent_classes[parent_classes.index(CachedVarOperation) + 1]
|
next_class = parent_classes[parent_classes.index(CachedVarOperation) + 1]
|
||||||
|
|
||||||
@ -1611,7 +1611,7 @@ class CachedVarOperation:
|
|||||||
"""
|
"""
|
||||||
return hash(
|
return hash(
|
||||||
(
|
(
|
||||||
self.__class__.__name__,
|
type(self).__name__,
|
||||||
*[
|
*[
|
||||||
getattr(self, field.name)
|
getattr(self, field.name)
|
||||||
for field in dataclasses.fields(self) # type: ignore
|
for field in dataclasses.fields(self) # type: ignore
|
||||||
@ -1733,7 +1733,7 @@ class CallableVar(Var):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the object.
|
The hash of the object.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self.original_var))
|
return hash((type(self).__name__, self.original_var))
|
||||||
|
|
||||||
|
|
||||||
RETURN_TYPE = TypeVar("RETURN_TYPE")
|
RETURN_TYPE = TypeVar("RETURN_TYPE")
|
||||||
|
@ -1012,7 +1012,7 @@ class LiteralNumberVar(LiteralVar, NumberVar):
|
|||||||
Returns:
|
Returns:
|
||||||
int: The hash value of the object.
|
int: The hash value of the object.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._var_value))
|
return hash((type(self).__name__, self._var_value))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, value: float | int, _var_data: VarData | None = None):
|
def create(cls, value: float | int, _var_data: VarData | None = None):
|
||||||
@ -1064,7 +1064,7 @@ class LiteralBooleanVar(LiteralVar, BooleanVar):
|
|||||||
Returns:
|
Returns:
|
||||||
int: The hash value of the object.
|
int: The hash value of the object.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._var_value))
|
return hash((type(self).__name__, self._var_value))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, value: bool, _var_data: VarData | None = None):
|
def create(cls, value: bool, _var_data: VarData | None = None):
|
||||||
|
@ -362,7 +362,7 @@ class LiteralObjectVar(CachedVarOperation, ObjectVar[OBJECT_TYPE], LiteralVar):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the var.
|
The hash of the var.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._js_expr))
|
return hash((type(self).__name__, self._js_expr))
|
||||||
|
|
||||||
@cached_property_no_lock
|
@cached_property_no_lock
|
||||||
def _cached_get_all_var_data(self) -> VarData | None:
|
def _cached_get_all_var_data(self) -> VarData | None:
|
||||||
|
@ -667,7 +667,7 @@ class LiteralStringVar(LiteralVar, StringVar[str]):
|
|||||||
Returns:
|
Returns:
|
||||||
The hash of the var.
|
The hash of the var.
|
||||||
"""
|
"""
|
||||||
return hash((self.__class__.__name__, self._var_value))
|
return hash((type(self).__name__, self._var_value))
|
||||||
|
|
||||||
def json(self) -> str:
|
def json(self) -> str:
|
||||||
"""Get the JSON representation of the var.
|
"""Get the JSON representation of the var.
|
||||||
|
@ -73,7 +73,7 @@ def StateInheritance():
|
|||||||
def on_click_other_mixin(self):
|
def on_click_other_mixin(self):
|
||||||
self.other_mixin_clicks += 1
|
self.other_mixin_clicks += 1
|
||||||
self.other_mixin = (
|
self.other_mixin = (
|
||||||
f"{self.__class__.__name__}.clicked.{self.other_mixin_clicks}"
|
f"{type(self).__name__}.clicked.{self.other_mixin_clicks}"
|
||||||
)
|
)
|
||||||
|
|
||||||
class Base1(Mixin, rx.State):
|
class Base1(Mixin, rx.State):
|
||||||
|
@ -46,7 +46,7 @@ def test_default_primary_key(model_default_primary: Model):
|
|||||||
Args:
|
Args:
|
||||||
model_default_primary: Fixture.
|
model_default_primary: Fixture.
|
||||||
"""
|
"""
|
||||||
assert "id" in model_default_primary.__class__.__fields__
|
assert "id" in type(model_default_primary).__fields__
|
||||||
|
|
||||||
|
|
||||||
def test_custom_primary_key(model_custom_primary: Model):
|
def test_custom_primary_key(model_custom_primary: Model):
|
||||||
@ -55,7 +55,7 @@ def test_custom_primary_key(model_custom_primary: Model):
|
|||||||
Args:
|
Args:
|
||||||
model_custom_primary: Fixture.
|
model_custom_primary: Fixture.
|
||||||
"""
|
"""
|
||||||
assert "id" not in model_custom_primary.__class__.__fields__
|
assert "id" not in type(model_custom_primary).__fields__
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings(
|
@pytest.mark.filterwarnings(
|
||||||
|
@ -1698,7 +1698,7 @@ async def test_state_manager_modify_state(
|
|||||||
assert not state_manager._states_locks[token].locked()
|
assert not state_manager._states_locks[token].locked()
|
||||||
|
|
||||||
# separate instances should NOT share locks
|
# separate instances should NOT share locks
|
||||||
sm2 = state_manager.__class__(state=TestState)
|
sm2 = type(state_manager)(state=TestState)
|
||||||
assert sm2._state_manager_lock is state_manager._state_manager_lock
|
assert sm2._state_manager_lock is state_manager._state_manager_lock
|
||||||
assert not sm2._states_locks
|
assert not sm2._states_locks
|
||||||
if state_manager._states_locks:
|
if state_manager._states_locks:
|
||||||
|
Loading…
Reference in New Issue
Block a user