| 1361 | |
| 1362 | |
| 1363 | def _idval( |
| 1364 | val: object, |
| 1365 | argname: str, |
| 1366 | idx: int, |
| 1367 | idfn: Optional[Callable[[Any], Optional[object]]], |
| 1368 | nodeid: Optional[str], |
| 1369 | config: Optional[Config], |
| 1370 | ) -> str: |
| 1371 | if idfn: |
| 1372 | try: |
| 1373 | generated_id = idfn(val) |
| 1374 | if generated_id is not None: |
| 1375 | val = generated_id |
| 1376 | except Exception as e: |
| 1377 | prefix = f"{nodeid}: " if nodeid is not None else "" |
| 1378 | msg = "error raised while trying to determine id of parameter '{}' at position {}" |
| 1379 | msg = prefix + msg.format(argname, idx) |
| 1380 | raise ValueError(msg) from e |
| 1381 | elif config: |
| 1382 | hook_id: Optional[str] = config.hook.pytest_make_parametrize_id( |
| 1383 | config=config, val=val, argname=argname |
| 1384 | ) |
| 1385 | if hook_id: |
| 1386 | return hook_id |
| 1387 | |
| 1388 | if isinstance(val, STRING_TYPES): |
| 1389 | return _ascii_escaped_by_config(val, config) |
| 1390 | elif val is None or isinstance(val, (float, int, bool, complex)): |
| 1391 | return str(val) |
| 1392 | elif isinstance(val, Pattern): |
| 1393 | return ascii_escaped(val.pattern) |
| 1394 | elif val is NOTSET: |
| 1395 | # Fallback to default. Note that NOTSET is an enum.Enum. |
| 1396 | pass |
| 1397 | elif isinstance(val, enum.Enum): |
| 1398 | return str(val) |
| 1399 | elif isinstance(getattr(val, "__name__", None), str): |
| 1400 | # Name of a class, function, module, etc. |
| 1401 | name: str = getattr(val, "__name__") |
| 1402 | return name |
| 1403 | return str(argname) + str(idx) |
| 1404 | |
| 1405 | |
| 1406 | def _idvalset( |