question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Bring typing aliases into beartype

See original GitHub issue

As 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
positacommented, Jan 14, 2022

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. 🙇💕

1reaction
leyceccommented, Jan 14, 2022

…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 from beartype.typing rather than typing. Exporting beartype.typing to a new third-party beartype_typing package would mean adding our first mandatory runtime dependency to beartype, which would (in turn) complicate packaging beartype for everything other than the pip ecosystem. This means conda, brew, macports, and emerge. 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 refactoring beartype.typing to import from a new private beartype._overload submodule: e.g.,

# In "beartype.typing":
import beartype._overload.beartype_overload as overload

Yup. beartype.typing just went incestuous. Slash-and-burning beartype.typing into beartype_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 on typing by assimilating and fundamentally repurposing all of the insane things in typing 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]. 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found