[Feature Request] Bring typing aliases into beartype
See original GitHub issueAs said in README.md, there are some compatibility problems with typing. Here’s my compat.py
. I hope similar thing exists in the beartype
library.
Edit: bugfixes
import logging
import sys
from abc import *
from enum import Enum
from typing import (Any, Callable, Dict, Generic, Iterable, Iterator, List,
Optional, Set, Tuple, TypeVar, Union, cast) # Add more
from types import (FunctionType, MethodType)
# handle type annotation changes in PEP 3107, 484, 526, 544, 560, 563, 585
versions = (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
if versions > (3, 8, 8):
Dict = dict
List = list
Set = set
Tuple = tuple
import collections.abc
Iterable = collections.abc.Iterable
Iterator = collections.abc.Iterator
if versions >= (3, 9, 2):
Callable = collections.abc.Callable
else:
Callable = collections.abc.Callable
logging.warning("collections.abc.Callable in Python 3.9.1 is broken")
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (7 by maintainers)
Top Results From Across the Web
The Future Sound of Beartype: Going Deep on Type-checking
Beartype 0.9.0 intends to extend deep type-checking support to parametrized type hints (i.e., type hints subscripted by one or more type variables). I...
Read more >Python Type Checking (Guide) - Real Python
In this guide, you'll look at Python type checking. ... Example: A Deck of Cards; Sequences and Mappings; Type Aliases; Functions Without Return...
Read more >Annotation issues at runtime - mypy 0.991 documentation
Annotation issues at runtime#. Idiomatic use of type annotations can sometimes run up against what a given version of Python considers legal code....
Read more >Python's “type hints” are a bit of a disappointment to me
I agree this is useful, but to me the most useful feature of types are the self-documentation. It's crazy the difference between a...
Read more >Beartype: Unbearably fast O(1) runtime type-checking in pure ...
from beartype.vale import Is >>> from typing import Annotated ... Beartype brings Rust- and C++-inspired zero-cost abstractions into the lawless world of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I now stand educated, humbled, and grateful. Having achieved enlightenment (or at least what I assume is enlightenment, as my left eye is now twitching), I cannot help but look back upon the naiveté of my earlier inquiry as not even wrong. My many thanks for your customarily thorough treatment of this subject, no matter the carelessness or ignorance with which I raised it. 🙇💕
…heh. My bum left eye is now twitching. Laziness never prevails by doing more work, @posita! Never! That’s how busyness prevails. The battle lines are drawn. Now, we heroic few are all called upon to choose a side.
Pragmatically, the remainder of the
beartype
codebase is being slyly refactored to preferentially import frombeartype.typing
rather thantyping
. Exportingbeartype.typing
to a new third-partybeartype_typing
package would mean adding our first mandatory runtime dependency tobeartype
, which would (in turn) complicate packagingbeartype
for everything other than thepip
ecosystem. This meansconda
,brew
,macports
, andemerge
. And @harens already got enough to do.But that’s not all… Resolving issue #54 “sanely” means redefining the
@beartype.typing.overload
decorator in a@beartype
-specific manner – probably by internally refactoringbeartype.typing
to import from a new privatebeartype._overload
submodule: e.g.,Yup.
beartype.typing
just went incestuous. Slash-and-burningbeartype.typing
intobeartype_typing
prevents us from going incestuous – which we gotta do to solve our problems.Ultimately, the overarching goal for
beartype.typing
is to go The Borg ontyping
by assimilating and fundamentally repurposing all of the insane things intyping
into less insane things. Bonus points if we do this like a masterless ninja on a moonlit night [read: without mypy or CPython devs noticing]. 😉