Skip to content

Commit

Permalink
Reiterables x 10.
Browse files Browse the repository at this point in the history
This commit is the next in a commit chain deeply type-checking
**reiterables** (i.e., collections satisfying the
`collections.abc.Collection` protocol with guaranteed `O(1)` read-only
access to *only* the first collection item), en-route to *finally*
resolving feature request #167 kindly submitted by the perennial
brilliant @langfield (...*how I miss that awesome guy!*) several
lifetimes ago back when I was probably a wandering vagabond Buddhist
monk with a bad attitude, a begging bowl the size of my emaciated torso,
and an honestly pretty cool straw hat that glinted dangerously in the
firelight. Note that reiterables include *all* containers matched by one
or more of the following PEP 484- or 585-compliant type hints:

* `frozenset[...]`.
* `set[...]`.
* `collections.deque[...]`.
* `collections.abc.Collection[...]`.
* `collections.abc.KeysView[...]`.
* `collections.abc.MutableSet[...]`.
* `collections.abc.Set[...]`.
* `collections.abc.ValuesView[...]`.
* `typing.AbstractSet[...]`.
* `typing.Collection[...]`.
* `typing.Deque[...]`.
* `typing.FrozenSet[...]`.
* `typing.KeysView[...]`.
* `typing.MutableSet[...]`.
* `typing.Set[...]`.
* `typing.ValuesView[...]`.

Specifically, this commit continues reducing problematic DRY (Don't
Repeat Yourself) violations in @beartype's internal type-checking code
generator. (*Creamy dream!*)
  • Loading branch information
leycec committed Jun 20, 2024
1 parent 3ca08e4 commit c1bed40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
3 changes: 3 additions & 0 deletions beartype/_check/code/snip/codesnipstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
This private submodule is *not* intended for importation by downstream callers.
'''

#FIXME: Refactor the gutted remainder of this submodule into new submodules
#residing in the new "beartype._data.code.pep" subpackage, please. *sigh*

# ....................{ IMPORTS }....................
from beartype._data.hint.datahinttyping import CallableStrFormat

Expand Down
18 changes: 4 additions & 14 deletions beartype/_decor/wrap/_wrapargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ def code_check_args(decor_meta: BeartypeDecorMeta) -> str:
arg_kind: ArgKind = None # type: ignore[assignment]
arg_name: str = None # type: ignore[assignment]

# Default value of this parameter if this parameter is optional *OR* the
# "ArgMandatory" singleton otherwise (i.e., if this parameter is mandatory).
arg_default: object = None
#FIXME: Uncomment as needed, please. *sigh*
# # Default value of this parameter if this parameter is optional *OR* the
# # "ArgMandatory" singleton otherwise (i.e., if this parameter is mandatory).
# arg_default: object = None

# For the 0-based index of each parameter accepted by that callable and the
# "ParameterMeta" object describing this parameter (in declaration order)...
Expand Down Expand Up @@ -165,17 +166,6 @@ def code_check_args(decor_meta: BeartypeDecorMeta) -> str:
arg_default,
) = arg_meta

# #FIXME: [SPEED] Optimize this by assigning all at once via tuple
# #unpacking, please. See "codemake" for similar optimizations.
# # Kind and name of this parameter.
# arg_kind: ArgKind = arg_meta[ARG_META_INDEX_KIND] # type: ignore[assignment]
# arg_name: str = arg_meta[ARG_META_INDEX_NAME] # type: ignore[assignment]
#
# # Default value of this parameter if this parameter is optional *OR* the
# # "ArgMandatory" singleton otherwise (i.e., if this parameter is
# # mandatory).
# arg_default: object = arg_meta[ARG_META_INDEX_DEFAULT]

# Type hint annotating this parameter if any *OR* the sentinel
# placeholder otherwise (i.e., if this parameter is unannotated).
#
Expand Down
12 changes: 6 additions & 6 deletions beartype/_util/func/arg/utilfuncargiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def iter_func_args(
# syntax governing the latter is overly verbose and largely unhelpful.
) -> Iterable[ArgMeta]:
'''
Generator yielding one **parameter metadata tuple** (i.e., tuple whose
items describe a single parameter) for each parameter accepted by the
passed pure-Python callable.
Generator yielding one **parameter metadata tuple** (i.e., tuple whose items
describe a single parameter) for each parameter accepted by the passed
pure-Python callable.
For consistency with the official grammar for callable signatures
standardized by :pep:`570`, this generator is guaranteed to yield parameter
Expand Down Expand Up @@ -223,9 +223,9 @@ def iter_func_args(
descriptor (rather than the low-level parameters accepted by the unbound
method encapsulated by this bound method descriptor). While the default
behaviour is typically desirable, valid use cases for the non-default
behaviour do exist (e.g., crudely detecting that callable's kind based
on whether the unbound method encapsulated by this bound method
descriptor accepts a first parameter named ``cls`` or ``self``).
behaviour do exist (e.g., crudely detecting the kind of that based on
whether the unbound method encapsulated by this bound method descriptor
accepts a first parameter named ``cls`` or ``self``).
The default behaviour enables:
Expand Down

0 comments on commit c1bed40

Please sign in to comment.