Skip to content

Commit

Permalink
Added more Can types
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham committed Feb 24, 2024
1 parent f7ad8f4 commit 204d1ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
28 changes: 16 additions & 12 deletions optype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'CanCeil',
'CanComplex',
'CanContains',
'CanDel',
'CanDelattr',
'CanDelete',
'CanDelitem',
Expand All @@ -30,7 +29,6 @@
'CanFormat',
'CanGe',
'CanGet',
'CanGetBound',
'CanGetattr',
'CanGetattribute',
'CanGetitem',
Expand All @@ -50,7 +48,6 @@
'CanITruediv',
'CanIXor',
'CanIndex',
'CanInitSubclass',
'CanInt',
'CanInvert',
'CanIter',
Expand Down Expand Up @@ -103,15 +100,20 @@
'CanWith',
'CanXor',
'HasAnnotations',
'HasClass',
'HasCode',
'HasDict',
'HasDoc',
'HasFunc',
'HasMatchArgs',
'HasModule',
'HasName',
'HasNames',
'HasQualname',
'HasWeakCallableProxy',
'HasWeakProxy',
'HasWeakReference',
'HasSelf',
'HasSlots',
'HasTypeParams',
'HasWrapped',
'__version__',
)

Expand All @@ -134,7 +136,6 @@
CanCeil,
CanComplex,
CanContains,
CanDel,
CanDelattr,
CanDelete,
CanDelitem,
Expand All @@ -149,7 +150,6 @@
CanFormat,
CanGe,
CanGet,
CanGetBound,
CanGetattr,
CanGetattribute,
CanGetitem,
Expand All @@ -169,7 +169,6 @@
CanITruediv,
CanIXor,
CanIndex,
CanInitSubclass,
CanInt,
CanInvert,
CanIter,
Expand Down Expand Up @@ -224,15 +223,20 @@
)
from ._has import (
HasAnnotations,
HasClass,
HasCode,
HasDict,
HasDoc,
HasFunc,
HasMatchArgs,
HasModule,
HasName,
HasNames,
HasQualname,
HasWeakCallableProxy,
HasWeakProxy,
HasWeakReference,
HasSelf,
HasSlots,
HasTypeParams,
HasWrapped,
)


Expand Down
41 changes: 16 additions & 25 deletions optype/_can.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# ruff: noqa: PYI034
from collections.abc import Generator
from collections.abc import Generator # sadge :(
from types import TracebackType
from typing import (
Any,
Protocol,
overload,
override,
runtime_checkable,
)
from typing import Any, Protocol, overload, override, runtime_checkable


# Iterator types
Expand All @@ -25,12 +19,9 @@ def __iter__(self) -> Vs: ...
# 3.3.1. Basic customization
# https://docs.python.org/3/reference/datamodel.html#basic-customization

# TODO: __new__
# TODO: __init__

@runtime_checkable
class CanDel(Protocol):
def __del__(self) -> Any: ...
# @runtime_checkable
# class CanDel(Protocol):
# def __del__(self) -> Any: ...

@runtime_checkable
class CanRepr[Y: str](Protocol):
Expand Down Expand Up @@ -146,16 +137,16 @@ def __delete__(self, __obj: T) -> Any: ...
# 3.3.3. Customizing class creation
# https://docs.python.org/3/reference/datamodel.html#customizing-class-creation

@runtime_checkable
class CanInitSubclass[**Ps](Protocol):
# no positional-only are allowed
# cannot `Unpack` type args: https://github.com/python/typing/issues/1399
# workaround: use `**Ps` instead of `Ps: TypedDict`
def __init_subclass__(
cls,
*__dont_use_these_args: Ps.args,
**__kwargs: Ps.kwargs,
) -> Any: ...
# @runtime_checkable
# class CanInitSubclass[**Ps](Protocol):
# # no positional-only are allowed
# # cannot `Unpack` type args: https://github.com/python/typing/issues/1399
# # workaround: use `**Ps` instead of `Ps: TypedDict`
# def __init_subclass__(
# cls,
# *__dont_use_these_args: Ps.args,
# **__kwargs: Ps.kwargs,
# ) -> Any: ...

@runtime_checkable
class CanSetName[T](Protocol):
Expand Down Expand Up @@ -587,7 +578,7 @@ class CanAsyncWith[V, R](CanAenter[V], CanAexit[R], Protocol):

# Module `abc`
# https://docs.python.org/3/library/abc.html
# TODO: CanSubclasshook
# TODO: CanSubclasshook?


# Module `copy`
Expand Down

0 comments on commit 204d1ef

Please sign in to comment.