graspologic-org / graspologic

Python package for graph statistics

Home Page:https://graspologic-org.github.io/graspologic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update type hinting to follow PEP 585

bdpedigo opened this issue · comments

Is your feature request related to a problem? Please describe.

I am getting the following warning

/Users/bpedigo/JHU_code/bilateral/.venv/lib/python3.9/site-packages/beartype/_util/hint/pep/utilpeptest.py:396: 
BeartypeDecorHintPepDeprecatedWarning: Type hint typing.List[scipy.sparse.csr.csr_matrix] deprecated by PEP 585. To 
resolve this, globally replace this hint by the equivalent PEP 585 type hint (e.g., "typing.List[int]" by "list[int]"). 
See also:
    https://www.python.org/dev/peps/pep-0585
  warn(warning_message, BeartypeDecorHintPepDeprecatedWarning)

Describe the solution you'd like

Should update anywhere in the code we use typing.List to be just list[], I think? That's just what it sounds like from a cursory glance at https://www.python.org/dev/peps/pep-0585/ but I could be wrong.

Hi, I would like to work on this issue. Can you guide me further on what needs ti be done ^_^

Hi @himanshu007-creator, sure, but first it would help me if you could clarify in the above what you don't understand

I would be sending a PR soo, but please reconfirm, what i have concluded from the issue description is that we have to update all references of typing.List with list[]

PEP 585 is a Python 3.9 thing, backwards-compatible to 3.7 with a future import. If we are still targeting 3.6 I don't think that we can use it.

Can we disable this warning?

Oh interesting. In that case, @himanshu007-creator why don't you hold off until we can discuss the best way to proceed.

This feels like a silly reason to remove 3.6 support, not sure if there are any other reasons to do so that anyone knows of?

I know in the past @daxpryce has been anti-suppress-warnings-for-the-user (I think?) but here it feels perhaps warranted if this is always going to pop up no matter what the user is doing. Thoughts?

While perambulating in an exhausted late-night stupor through this exciting project, I couldn't help but notice this issue. As Mr. Beartype, I am the culprit responsible for everyone's pain here. 😞

The core issue is that PEP 585 deprecates most of PEP 484. Specifically, most of the typing module (including typing.List) will be going away by 2024. You have two options here:

  • Easy way. The easy way is, as @bdpedigo suggests, to just unilaterally squelch this warning with an ignore warning filter on BeartypeDecorHintPepDeprecatedWarning. Since this is currently the only type of deprecated type hint, this is a decent temporary solution. Of course, this solution will still fail sometime in 2024 with fiery explosions. Thanks alot, Guido! If that wasn't easy enough, here are two even easier ways to do this with differing tradeoffs depending on who you want to suffer the most – you or your awesome userbase:
# Do it globally for everyone, whether they want you to or not!
# This is the "Make Users Suffer" option.
from beartype.roar import BeartypeDecorHintPepDeprecatedWarning
from warnings import filterwarnings
filterwarnings("ignore", category=BeartypeDecorHintPepDeprecatedWarning)
...

# Do it locally only for you! (Hope you like globally increasing your
# indentation level in every single package module.)
# This is the "Make Yourself Suffer" option.
from beartype.roar import BeartypeDecorHintPepDeprecatedWarning
from warnings import catch_warnings, filterwarnings
with catch_warnings():
    filterwarnings("ignore", category=BeartypeDecorHintPepDeprecatedWarning)
    ...
  • Hard way. The hard way is to use type aliases to conditionally annotate callables with either PEP 484 or 585 type hints depending on the major version of the current Python interpreter. Since this is life, the hard way is also the best way – but it's also hard. For example, you might define a new private graspologic._typing submodule resembling:
from sys import version_info

if version_info >= (3, 9):
    List = list
    Tuple = tuple
    ...
else:
    from typing import List, Tuple, ...

Then instead of importing List and Tuple from typing when annotating callables, you import List and Tuple from your private graspologic._typing submodule instead: e.g.,

# Instead of this...
from typing import List, Tuple

# ...just do this.
from graspologic._typing import List, Tuple

What could be simpler? gagging sounds faintly heard

And... I should just write this up as a FAQ entry already. May your pain be felt by no one else.

Beartype FAQ entry is now live. If there's anything else I can do to simplify your QA, ping me and it will be so. Thanks again, all! 🐻

@himanshu007-creator so yeah, hold off making any changes - @pbourke has this covered in his type-hint branch (or will, rather) - and we also want to wait on beartype 0.9 for that too.

So yeah! This is fun. I'm having fun. Are you having fun? I'm having fun.

wtb compiler pst

@leycec - I'm not trying to rush you at all, I'm just curious if you have a rough idea of when 0.9 magicks may happen?

Again, not trying to apply any pressure at all, just coming up with some rough plans :)

@leycec appears in a magical puff of suspiciously pungent purple haze

The short answer is: By this Friday, on my honourable blood oath.

Thanks for pinging me back, Dax. And might I say, what a beautiful running dog through nostalgic fields of gold in your GitHub avatar. Our Maine Coon cat is rumbling with jealousy-tinged fear.

I've had your wonderful team in the back of my mind for the past several days, as I recall reading somewhere that your hotly anticipated next stable release is blocking on the upcoming beartype 0.9.0 released. Ugh! It's always "One more thing, I swear it!" with people like me.

All pending issues and pull requests have long since been resolved. Our last action item is deduplicating PEP 585 type hints, reducing both time complexity at decoration time and space complexity for the duration of the active Python process. Thankfully, we're nearly there. Let's see what caffeine can do for us all tonight. ☕

Also, just this:

wtb compiler pst

kek kek kek

Capitalist WoW market intensifies.

PEP 585 deduplication is a go. Tests are a go. This can only mean one thing: beartype 0.9.0 is a go and will (maybe) land Friday morning – or may my GitHub avatar be replaced by screaming cats.

dramatic meme

land-on-my-feet-ulysses

edit: I know, squirrels are not bears, but it was the closest I was going to find to a non-human-animal-super-hero-landing

I feel that untrammelled power of the wilderness. It radiates like half-eaten acorn husks off the ripped body of Chad Squirrel.

I never knew something so scary could exist. As I peer ever closer, I see fathomless nebulae unfolding in the abyssal depths of the creature's eyes.

So I think this is sorted out with #889