Skip to content

Commit fa2e560

Browse files
authored
remove literal generic type parameters of Can* (#487)
2 parents d0840de + 46d91b1 commit fa2e560

File tree

9 files changed

+162
-274
lines changed

9 files changed

+162
-274
lines changed

README.md

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ This is why these `optype` interfaces don't accept generic type arguments.
364364
<td><code>do_int</code></td>
365365
<td><code>DoesInt</code></td>
366366
<td><code>__int__</code></td>
367-
<td><code>CanInt[+R: int = int]</code></td>
367+
<td><code>CanInt</code></td>
368368
</tr>
369369
<tr>
370370
<td><code>bool(_)</code></td>
@@ -378,72 +378,28 @@ This is why these `optype` interfaces don't accept generic type arguments.
378378
<td><code>do_bytes</code></td>
379379
<td><code>DoesBytes</code></td>
380380
<td><code>__bytes__</code></td>
381-
<td><code>CanBytes[+R: bytes = bytes]</code></td>
381+
<td><code>CanBytes</code></td>
382382
</tr>
383383
<tr>
384384
<td><code>str(_)</code></td>
385385
<td><code>do_str</code></td>
386386
<td><code>DoesStr</code></td>
387387
<td><code>__str__</code></td>
388-
<td><code>CanStr[+R: str = str]</code></td>
389-
</tr>
390-
</table>
391-
392-
> [!NOTE]
393-
> The `Can*` interfaces of the types that can used as `typing.Literal`
394-
> accept an optional type parameter `R`.
395-
> This can be used to indicate a literal return type,
396-
> for surgically precise typing, e.g. `None`, `True`, and `42` are
397-
> instances of `CanBool[Literal[False]]`, `CanInt[Literal[1]]`, and
398-
> `CanStr[Literal['42']]`, respectively.
399-
400-
These formatting methods are allowed to return instances that are a subtype
401-
of the `str` builtin. The same holds for the `__format__` argument.
402-
So if you're a 10x developer that wants to hack Python's f-strings, but only
403-
if your type hints are spot-on; `optype` is you friend.
404-
405-
<table>
406-
<tr>
407-
<th colspan="3" align="center">operator</th>
408-
<th colspan="2" align="center">operand</th>
409-
</tr>
410-
<tr>
411-
<td>expression</td>
412-
<th>function</th>
413-
<th>type</th>
414-
<td>method</td>
415-
<th>type</th>
388+
<td><code>CanStr</code></td>
416389
</tr>
417390
<tr>
418391
<td><code>repr(_)</code></td>
419392
<td><code>do_repr</code></td>
420393
<td><code>DoesRepr</code></td>
421394
<td><code>__repr__</code></td>
422-
<td><code>CanRepr[+R:str = str]</code></td>
395+
<td><code>CanRepr</code></td>
423396
</tr>
424397
<tr>
425398
<td><code>format(_, x)</code></td>
426399
<td><code>do_format</code></td>
427400
<td><code>DoesFormat</code></td>
428401
<td><code>__format__</code></td>
429-
<td><code>CanFormat[-T:str = str, +R:str = str]</code></td>
430-
</tr>
431-
</table>
432-
433-
Additionally, `optype` provides protocols for types with (custom) *hash* or
434-
*index* methods:
435-
436-
<table>
437-
<tr>
438-
<th colspan="3" align="center">operator</th>
439-
<th colspan="2" align="center">operand</th>
440-
</tr>
441-
<tr>
442-
<td>expression</td>
443-
<th>function</th>
444-
<th>type</th>
445-
<td>method</td>
446-
<th>type</th>
402+
<td><code>CanFormat</code></td>
447403
</tr>
448404
<tr>
449405
<td><code>hash(_)</code></td>
@@ -460,7 +416,7 @@ Additionally, `optype` provides protocols for types with (custom) *hash* or
460416
<td><code>do_index</code></td>
461417
<td><code>DoesIndex</code></td>
462418
<td><code>__index__</code></td>
463-
<td><code>CanIndex[+R: int = int]</code></td>
419+
<td><code>CanIndex</code></td>
464420
</tr>
465421
</table>
466422

@@ -1434,7 +1390,7 @@ Additionally, there is `optype.CanAIterSelf[R]`, with both the
14341390
<td><code>do_len</code></td>
14351391
<td><code>DoesLen</code></td>
14361392
<td><code>__len__</code></td>
1437-
<td><code>CanLen[+R:int=int]</code></td>
1393+
<td><code>CanLen</code></td>
14381394
</tr>
14391395
<tr>
14401396
<td>
@@ -1444,7 +1400,7 @@ Additionally, there is `optype.CanAIterSelf[R]`, with both the
14441400
<td><code>do_length_hint</code></td>
14451401
<td><code>DoesLengthHint</code></td>
14461402
<td><code>__length_hint__</code></td>
1447-
<td><code>CanLengthHint[+R:int=int]</code></td>
1403+
<td><code>CanLengthHint</code></td>
14481404
</tr>
14491405
<tr>
14501406
<td><code>_[k]</code></td>
@@ -1491,7 +1447,7 @@ Additionally, there is `optype.CanAIterSelf[R]`, with both the
14911447
<td><code>__reversed__</code></td>
14921448
<td>
14931449
<code>CanReversed[+R]</code>, or<br>
1494-
<code>CanSequence[-I, +V, +N=int]</code>
1450+
<code>CanSequence[-I, +V]</code>
14951451
</td>
14961452
</tr>
14971453
</table>
@@ -1526,7 +1482,7 @@ specific and flexible `collections.abc.Sequence[V]`.
15261482
<td><code>do_getattr</code></td>
15271483
<td><code>DoesGetattr</code></td>
15281484
<td><code>__getattr__</code></td>
1529-
<td><code>CanGetattr[-K:str=str, +V=object]</code></td>
1485+
<td><code>CanGetattr[+V=object]</code></td>
15301486
</tr>
15311487
<tr>
15321488
<td>
@@ -1536,7 +1492,7 @@ specific and flexible `collections.abc.Sequence[V]`.
15361492
<td><code>do_setattr</code></td>
15371493
<td><code>DoesSetattr</code></td>
15381494
<td><code>__setattr__</code></td>
1539-
<td><code>CanSetattr[-K:str=str, -V=object]</code></td>
1495+
<td><code>CanSetattr[-V=object]</code></td>
15401496
</tr>
15411497
<tr>
15421498
<td>
@@ -1546,14 +1502,14 @@ specific and flexible `collections.abc.Sequence[V]`.
15461502
<td><code>do_delattr</code></td>
15471503
<td><code>DoesDelattr</code></td>
15481504
<td><code>__delattr__</code></td>
1549-
<td><code>CanDelattr[-K:str=str]</code></td>
1505+
<td><code>CanDelattr</code></td>
15501506
</tr>
15511507
<tr>
15521508
<td><code>dir(_)</code></td>
15531509
<td><code>do_dir</code></td>
15541510
<td><code>DoesDir</code></td>
15551511
<td><code>__dir__</code></td>
1556-
<td><code>CanDir[+R:CanIter[CanIterSelf[str]]]</code></td>
1512+
<td><code>CanDir[+R: Iterable[str]]</code></td>
15571513
</tr>
15581514
</table>
15591515

@@ -1683,7 +1639,7 @@ Interfaces for [descriptors](https://docs.python.org/3/howto/descriptor.html).
16831639
<tr>
16841640
<td><code>class T: d = _</code></td>
16851641
<td><code>__set_name__</code></td>
1686-
<td><code>CanSetName[-T, -N: str = str]</code></td>
1642+
<td><code>CanSetName[-T]</code></td>
16871643
</tr>
16881644
</table>
16891645

@@ -1704,7 +1660,7 @@ Interfaces for emulating buffer types using the [buffer protocol][BP].
17041660
<tr>
17051661
<td><code>v = memoryview(_)</code></td>
17061662
<td><code>__buffer__</code></td>
1707-
<td><code>CanBuffer[-T: int = int]</code></td>
1663+
<td><code>CanBuffer</code></td>
17081664
</tr>
17091665
<tr>
17101666
<td><code>del v</code></td>

0 commit comments

Comments
 (0)