Skip to content

Commit

Permalink
"typing_extensions.Annotated" x 21.
Browse files Browse the repository at this point in the history
This commit is the next in a commit chain adding transparent support
for the third-party `typing_extensions.Annotated` type hint back-ported
to Python < 3.9, en route to resolving #34. Once finalized, this will
enable usage of beartype validators under Python < 3.9 via this hint.
Specifically, this commit continues disastrously breaking literally
everything by continuing to disembowel the feckless
`beartype._util.hint.data.pep.datapep` submodule and its untrustworthy
`beartype._util.hint.data.pep.proposal` crony subpackage in favour of
`beartype._util.hint.data.pep.sign`, which is the only subpackage left
standing. Save us from our reckless selves, GitHub! (*Inundated exudate!*)
  • Loading branch information
leycec committed Jul 8, 2021
1 parent 904499a commit e7c96ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
14 changes: 7 additions & 7 deletions beartype/_util/data/hint/pep/datapeprepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@


# Initialized with automated inspection below in the _init() function.
HINT_PEP484_BARE_REPRS_DEPRECATED: FrozenSet[str] = None # type: ignore[assignment]
HINT_PEP484_BARE_REPRS_DEPRECATED: FrozenSet[str] = set() # type: ignore[assignment]
'''
Frozen set of all **bare deprecated** :pep:`484`-compliant **type hint
representations** (i.e., machine-readable strings returned by the :func:`repr`
Expand Down Expand Up @@ -254,6 +254,7 @@ def _init() -> None:
# Permit redefinition of these globals below.
global \
HINT_BARE_REPRS_DEPRECATED, \
HINT_PEP484_BARE_REPRS_DEPRECATED, \
HINT_REPRS_IGNORABLE

# ..................{ HINTS }..................
Expand All @@ -263,7 +264,7 @@ def _init() -> None:
# ..................{ HINTS ~ deprecated }..................
# Set of the unqualified names of all deprecated PEP 484-compliant typing
# attributes.
_HINT_PEP484_TYPING_ATTR_NAMES_DEPRECATED: Set[str] = {}
_HINT_PEP484_TYPING_ATTR_NAMES_DEPRECATED: Set[str] = set()

# If the active Python interpreter targets Python >= 3.9 and thus
# supports PEP 585, add the names of all deprecated PEP 484-compliant
Expand Down Expand Up @@ -427,11 +428,10 @@ def _init() -> None:
f'{typing_module_name}.{hint_type_basename}'] = hint_sign

# ..................{ SYNTHESIS }..................
# Synthesize the frozen set of all bare deprecated PEP-compliant type hint
# representations from lower-level PEP-specific sets.
HINT_BARE_REPRS_DEPRECATED = frozenset(HINT_PEP484_BARE_REPRS_DEPRECATED)

# Freeze the set of all shallowly ignorable type hint representations.
# Freeze all relevant global sets for safety.
HINT_PEP484_BARE_REPRS_DEPRECATED = frozenset(
HINT_PEP484_BARE_REPRS_DEPRECATED)
HINT_BARE_REPRS_DEPRECATED = HINT_PEP484_BARE_REPRS_DEPRECATED
HINT_REPRS_IGNORABLE = frozenset(HINT_REPRS_IGNORABLE)

# Initialize this submodule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ def test_die_unless_hint_pep_sign_supported() -> None:
BeartypeDecorHintPepException,
BeartypeDecorHintPepUnsupportedException,
)
from beartype._util.data.hint.pep.sign.datapepsignset import (
HINT_SIGNS_SUPPORTED)
from beartype._util.hint.pep.utilhintpeptest import (
die_if_hint_pep_sign_unsupported)
from beartype._util.data.hint.pep.datapep import (
HINT_SIGNS_SUPPORTED)
from beartype_test.a00_unit.data.hint.data_hint import NOT_HINTS_PEP
from beartype_test.a00_unit.data.hint.pep.data_hintpep import (
HINTS_PEP_HASHABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,10 +1657,6 @@ def add_data(data_module: 'ModuleType') -> None:
if IS_PYTHON_AT_LEAST_3_7:
data_module.HINTS_PEP_META.extend((
# ..............{ UNSUBSCRIPTED }..............
# See the
# "beartype._util.data.hint.pep.datapep.TYPING_ATTR_TO_TYPE_ORIGIN"
# dictionary for detailed discussion.

# Unsubscripted "Hashable" attribute.
PepHintMetadata(
hint=Hashable,
Expand Down
49 changes: 24 additions & 25 deletions beartype_test/a00_unit/decor/code/test_codemain.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def test_codemain() -> None:
# BeartypeDecorHintPepDeprecatedWarning,
)
from beartype._util.utilobject import is_object_context_manager
from beartype._util.data.hint.pep.datapep import (
HINT_PEP_ATTRS_DEPRECATED)
from beartype_test.a00_unit.data.hint.data_hintmeta import (
PepHintMetadata,
PepHintPithSatisfiedMetadata,
PepHintPithUnsatisfiedMetadata,
)
Expand Down Expand Up @@ -91,28 +88,30 @@ def func_untyped(hint_param: hint_meta.hint) -> hint_meta.hint:
# Decorated callable declared below.
func_typed = None

# If this is a deprecated PEP-compliant type hint, declare this
# decorated callable under a context manager asserting this
# declaration to emit non-fatal deprecation warnings.
if (
isinstance(hint_meta, PepHintMetadata) and
hint_meta.pep_sign in HINT_PEP_ATTRS_DEPRECATED
):
#FIXME: For unknown and probably uninteresting reasons, the
#pytest.warns() context manager appears to be broken on our
#local machine. We have no recourse but to unconditionally
#ignore this warning at the module level. So much rage!
#FIXME: It's likely this has something to do with the fact that
#Python filters deprecation warnings by default. This is almost
#certainly a pytest issue. Since this has become fairly
#unctuous, we should probably submit a pytest issue report.
# with pytest.warns(BeartypeDecorHintPepDeprecatedWarning):
# func_typed = beartype(func_untyped)
func_typed = beartype(func_untyped)
# Else, this is *NOT* a deprecated PEP-compliant type hint. In this
# case, declare this decorated callable as is.
else:
func_typed = beartype(func_untyped)
#FIXME: For unknown and probably uninteresting reasons, the
#pytest.warns() context manager appears to be broken on our
#local machine. We have no recourse but to unconditionally
#ignore this warning at the module level. So much rage!
#FIXME: It's likely this has something to do with the fact that
#Python filters deprecation warnings by default. This is almost
#certainly a pytest issue. Since this has become fairly
#unctuous, we should probably submit a pytest issue report.
# # If this is a deprecated PEP-compliant type hint, declare this
# # decorated callable under a context manager asserting this
# # declaration to emit non-fatal deprecation warnings.
# if (
# isinstance(hint_meta, PepHintMetadata) and
# hint_meta.pep_sign in HINT_PEP_ATTRS_DEPRECATED
# ):
# with pytest.warns(BeartypeDecorHintPepDeprecatedWarning):
# func_typed = beartype(func_untyped)
# # Else, this is *NOT* a deprecated PEP-compliant type hint. In this
# # case, declare this decorated callable as is.
# else:
# func_typed = beartype(func_untyped)

# @beartype-generated wrapper function type-checking this callable.
func_typed = beartype(func_untyped)

# For each pith satisfying this hint...
for pith_satisfied_meta in hint_meta.piths_satisfied_meta:
Expand Down

0 comments on commit e7c96ed

Please sign in to comment.