pomcorn 0.8.1__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pomcorn might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pomcorn
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: Base implementation of Page Object Model
5
5
  Home-page: https://pypi.org/project/pomcorn/
6
6
  License: MIT
@@ -18,6 +18,7 @@ Classifier: Operating System :: OS Independent
18
18
  Classifier: Programming Language :: Python :: 3
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
23
  Requires-Dist: selenium (>=4.12)
23
24
  Project-URL: Documentation, http://pomcorn.rtfd.io/
@@ -1,3 +1,4 @@
1
+ import typing
1
2
  from inspect import isclass
2
3
  from typing import (
3
4
  Any,
@@ -207,6 +208,43 @@ class ListComponent(Generic[ListItemType, TPage], Component[TPage]):
207
208
  item_locator: locators.XPathLocator | None = None
208
209
  relative_item_locator: locators.XPathLocator | None = None
209
210
 
211
+ def __class_getitem__(cls, item: tuple[type, ...]) -> Any:
212
+ """Create parameterized versions of generic classes.
213
+
214
+ This method is called when the class is used as a parameterized type,
215
+ such as MyGeneric[int] or MyGeneric[List[str]].
216
+
217
+ We override this method to store values passed in generic parameters.
218
+
219
+ Args:
220
+ cls - The generic class itself.
221
+ item - The type used for parameterization.
222
+
223
+ Returns:
224
+ type: A parameterized version of the class with the specified type.
225
+
226
+ """
227
+ list_cls = super().__class_getitem__(item) # type: ignore
228
+ cls.__generic_parameters__ = item # type: ignore
229
+ return list_cls
230
+
231
+ def __init__(
232
+ self,
233
+ page: TPage,
234
+ base_locator: locators.XPathLocator | None = None,
235
+ wait_until_visible: bool = True,
236
+ ) -> None:
237
+ # If `_item_class` was not specified in `__init_subclass__`, this means
238
+ # that `ListComponent` is used as a parameterized type
239
+ # (e.g., `List[ItemClass, Page]`).
240
+ if isinstance(self._item_class, _EmptyValue):
241
+ # In this way we check the stored generic parameters and, if first
242
+ # from them is valid, set it as `_item_class`
243
+ first_generic_param = self.__generic_parameters__[0]
244
+ if self.is_valid_item_class(first_generic_param):
245
+ self._item_class = first_generic_param
246
+ super().__init__(page, base_locator, wait_until_visible)
247
+
210
248
  def __init_subclass__(cls) -> None:
211
249
  """Run logic for getting/overriding item_class attr for subclasses."""
212
250
  super().__init_subclass__()
@@ -297,10 +335,19 @@ class ListComponent(Generic[ListItemType, TPage], Component[TPage]):
297
335
  def is_valid_item_class(cls, item_class: Any) -> bool:
298
336
  """Check that specified ``item_class`` is valid.
299
337
 
300
- Valid `item_class` should be a class and subclass of ``Component``.
338
+ Valid ``item_class`` should be
339
+ * a class and subclass of ``Component``
340
+ * or TypeAlias based on ``Component``
301
341
 
302
342
  """
303
- return isclass(item_class) and issubclass(item_class, Component)
343
+ if isclass(item_class) and issubclass(item_class, Component):
344
+ return True
345
+
346
+ if isinstance(item_class, typing._GenericAlias): # type: ignore
347
+ type_alias = item_class.__origin__ # type: ignore
348
+ return isclass(type_alias) and issubclass(type_alias, Component)
349
+
350
+ return False
304
351
 
305
352
  def get_item_by_text(self, text: str) -> ListItemType:
306
353
  """Get list item by text."""
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pomcorn"
3
- version = "0.8.1"
3
+ version = "0.8.3"
4
4
  description = "Base implementation of Page Object Model"
5
5
  authors = [
6
6
  "Saritasa <pypi@saritasa.com>",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes