Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 13 22:13
    astrogewgaw starred jab/bidict
  • May 13 19:37
    pravirkr starred jab/bidict
  • May 13 07:49
    NIRVANALAN starred jab/bidict
  • May 12 23:36
    sniranjan starred jab/bidict
  • May 12 15:36
    jab locked #154
  • May 12 15:32
    jab commented #154
  • May 12 14:36
    gaborbernat commented #154
  • May 12 14:22
    jab commented #154
  • May 12 14:00
    gaborbernat commented #154
  • May 12 13:58
    jab commented #154
  • May 12 13:00
    gaborbernat commented #154
  • May 12 12:59
    gaborbernat commented #154
  • May 12 07:19
    koolmonkey starred jab/bidict
  • May 12 07:04
    dlax starred jab/bidict
  • May 12 00:07
    jab commented #154
  • May 12 00:05
    jab commented #154
  • May 09 22:01
    jab commented #179
  • May 09 21:55
    jab commented #178
  • May 09 21:53
    codecov[bot] commented #179
  • May 09 21:50
    jab opened #179
Bernát Gábor
@gaborbernat
AFAIU this only affects the invert function; so without you would be able to type everything else, just not invert
and make the plugin for the invert; but then users would need to install that for mypy
Ethan Smith
@ethanhs
^ this is correct
Joshua Bronson
@jab
@ethanhs @gaborbernat, thanks for the suggestion. Re "this only affects the inverse property", that may be true, but inverse accounts for an outsized share of a bidict's value, since it is not only a view of the inverse bidict, but also the main interface for getting and setting keys by value on the forward bidict. So I think the proposal to "type hint everything but inverse" (in a way that is understandable by mypy without any custom plugins) might provide a lot less value than you expect.
That said, a bidict user who never needed to use the inverse property would still get a lot of value out of the rest of its implementation of the MutableMapping interface, since it enforces the uniqueness of values constraint.
Joshua Bronson
@jab
But as a solo, voluntary maintainer of bidict who can only afford to work on bidict on nights and weekends, I unfortunately don't have the resources to devote to developing any custom mypy plugins at this time. And even if I did, I would be concerned that the effort required would not be worth the value provided by such a partial solution – how many users would actually use the plugin, how well would it integrate into everyone's various workflows, IDEs, continuous integration, etc. etc. Let me know if I'm missing something, but at this point the value proposition does not seem compelling enough.
Joshua Bronson
@jab
In the meantime, it does seem worth reporting back in all the relevant, open mypy/typing issues that they're currently holding back proper type hinting for data structure libraries like bidict, so that people know there are other very concrete use cases affected here. @ethanhs, given how active you've been in the mypy project and your greater level of understanding of what's needed, would you be willing to leave a quick comment to this effect on the relevant issue(s)?
Thanks so much again for taking the time to advise on this.
Joshua Bronson
@jab
Hi @/all, I'm thinking of removing BidirectionalMapping.__subclasshook__() (which allows any Mapping with an inverse attribute to be considered a BidirectionalMapping, even if it doesn't explicitly inherit from it), because it is fiddly, error-prone code (see #111) that appears to be unused based on GitHub code search. Wanted to check with you all though first. Any concerns or suggestions?
Richard Sanger
@rsanger
BidirectionalMapping.__subclasshook__() is not part of the API I have used, so no objection from me. If no one is using it, removing it seems reasonable.
Joshua Bronson
@jab
Thanks so much for letting me know, @rsanger, definitely validating to hear that!
Joshua Bronson
@jab
@/all, I just released bidict v0.20.0, with a bugfix (see #111) and some unused APIs removed. See https://bidict.rtfd.io/en/v0.20.0/changelog.html for details. Please upgrade when you can and let me know if you have any issues.
Joshua Bronson
@jab
Hi @ethanhs, I'm looking at type hints again for bidict, and I'm seeing an error with Python 3.6 that I'm not seeing with 3.7 or 3.8: "TypeError: weakref slot disallowed: either we already got one, or itemsize != 0". I assume this is PEP560, does that sound right? Is there any workaround you (or others you could refer me to) are aware of? See https://travis-ci.org/github/jab/bidict/jobs/713692506 for an example of the error and https://travis-ci.org/github/jab/bidict/builds/713725927 to see this works in Python > 3.6.
Ethan Smith
@ethanhs
PEP 560 only affects Python 3.9 and above. This is likely a change in the typing module in 3.7 that fixed what appears to be a bug?
Joshua Bronson
@jab
Thanks @ethanhs. Can you please clarify "PEP 560 only affects Python 3.9 and above"? I see "Python-Version: 3.7" at the top, and in the https://www.python.org/dev/peps/pep-0560/#hacks-and-bugs-that-will-be-removed-by-this-proposal section I see "_no_slots_copy hack, where we clean up the class dictionary on every subscription thus allowing generics with slots", which matches the fact that I'm seeing a problem with generics with slots on Python 3.6.
Joshua Bronson
@jab
And more immediately, what do you recommend I do next? If this is in fact not a known issue (as per my previous comment), and is rather a bug in Python 3.6 (which I see no existing report of in the BPO tracker), then, according to https://www.python.org/downloads/, Python 3.6 already has maintenance status "security fixes only". Do you nonetheless recommend filing a bug against 3.6, and seeing if someone suggests a workaround? Or just dropping support for 3.6 even though https://www.python.org/downloads/ says it's supported till 2021-12-23? Something else?
Ethan Smith
@ethanhs
Actually hmm yeah that may be something fixed by PEP 560, and it does change some of the internal machinery in 3.7
Ethan Smith
@ethanhs
I would recommend you file a bug. Even if they don't fix it, people more familiar with the typing module than I may be able to guide you to a workaround if one exists
Joshua Bronson
@jab
Thanks @ethanhs. Reported in https://bugs.python.org/issue41451 along with a minimal, working repro.
Joshua Bronson
@jab
@/all ICYMI, I submitted a PR adding type hints to bidict! jab/bidict#112

As I commented in the PR:
"""
Doesn't have to block merging, but there are a few places where I used # type: ignore internally that may actually be worth type checking. Maybe. (In many of these places though I suspect appeasing mypy would not be worth it, e.g. namedbidict and _invcls.) Open to suggestions.

One thing I had trouble with was using @typing.overload with __init__() and update(). For example, mypy rejects:

    @_t.overload
    def update(self, **kw: VT) -> None: ...
    @_t.overload
    def update(self, map: _t.Mapping[KT, VT], **kw: VT) -> None: ...
    @_t.overload
    def update(self, col: IterItems[KT, VT], **kw: VT) -> None: ...
    def update(self, *args: MapOrIterItems[KT, VT], **kw: VT) -> None:
        # (implementation here)

I think this may be a current limitation in mypy, so I left those without the overloads. If someone wants to suggest an alternative, I'll be happy to take another look.
"""

Joshua Bronson
@jab

Would much appreciate another pair of eyes on this if anyone is interested. Maybe the best way to review is to start at https://github.com/jab/bidict/blob/dev/bidict/_abc.py and then follow the suggested code review path in the header comments, focusing on the type hints. Please comment (or just react to the PR with :eyes:) if you're interested in reviewing, and I'll wait for feedback before I merge.

Thanks in advance to anyone who can help this lonely solo-maintainer make bidict's first type hints as good as can be! :heart:

Joshua Bronson
@jab
@/all, just merged #112 with type hints! Please run pip install 'git+https://github.com/jab/bidict.git' to try it out and let me know how well everything is working for you before I make a new release.
JeWe37
@JeWe37
hello, is there any multibimap implementation for python? something akin to what is described here for cpp: https://stackoverflow.com/questions/12174997/boostbimap-equivalent-of-bidirectional-multimap
i ve found myself in need of such a datastructure multiple times now and while it can be done fairly easily with multiple dictionaries, it is somewhat of a pain and not very readable. i havent really been able to find anything tho.
Joshua Bronson
@jab
Not that I know of. Curious to hear more about your use cases.
JeWe37
@JeWe37
well, i essentially have a dict of conditions upon the triggering of which a list of not necessarily unique actions is to be invoked. i now want conditions to be created such that no action is duplicated between different conditions. as such i have to or the conditions together and accumulate the elements according to the correct ORing of the condition. this is equivalent to simply adding all that i had in my original dict to a multibimap and then ORing the conditions and taking all the values for those new conditions as the actions to be triggered for them. you can of course do it without such a data structure, it just looks like this(which probably is still easier to read than my attempt at an explanation):
def reduce_or_add(d, reduce):
    seen = {}
    ret = defaultdict(set)
    for k, vs in d.items():
        for v in vs:
            if v in seen:
                ret[seen[v]].remove(v)
                seen[v] = reduce(k, seen[v])
                ret[seen[v]].add(v)
            else:
                ret[k].add(v)
                seen[v] = k
    return ret
JeWe37
@JeWe37
https://github.com/sushobhit27/bimap
i found this, but it does not appear to be updated, had multiple bugs when i downloaded it and features not exactly what i d call a user friendly interface
Joshua Bronson
@jab
@JeWe37 Sorry I havent had time to look into this yet. But in the meantime, just wanted to make sure you’ve seen the https://bidict.readthedocs.io/extending.html docs in case that could be useful to you.
JeWe37
@JeWe37
sadly that doesnt quite help me. for the time being it is not crucial by any means anyway, it was primarily in the interest of readability and coding efficiency for the future that i was curious.
Joshua Bronson
@jab
@/all, I just released bidict v0.21.0, the first version to support type hints! ⌨️ ✅ See https://bidict.rtfd.io/en/v0.21.0/changelog.html for the full changelog. Please upgrade when you can and let me know if you have any issues!
mbarkhau
@mbarkhau
I used this to get tox working on my local machine, perhaps this would be interesting for other new contributors: https://gist.github.com/mbarkhau/d38a4bf5d1b0c7b0f7f10c4bbd699e39
Joshua Bronson
@jab
Thanks @mbarkhau, though maybe better to use pyenv rather than conda.
(equally cross-platform but more minimal - just python versions and not a whole parallel universe)
mbarkhau
@mbarkhau
pyenv will install different versions of python?
Joshua Bronson
@jab
Yep, that’s one of its main functions
Joshua Bronson
@jab
Hi @/all, I’ll be hosting a sprint for bidict coming up on Friday, September 25 from about 10am to 5pm Eastern. We’ll use this chat room to share what we’re working on and coordinate. Look forward to seeing you there!
Isaac Good
@IsaacG
Howdy, @jab
Joshua Bronson
@jab
👋 @IsaacG, nice to see you here! Looking forward to hacking with you on Friday.
LEONID GILMAN
@leonidgman_gitlab
Hi @jab
Joshua Bronson
@jab
Hey @leonidgman_gitlab, great to see you here! 👋
Neil Tiwari
@neiltiwari
:wave: @jab
Joshua Bronson
@jab
👋@neiltiwari, welcome!
And welcome @/all to today's bidict Hack Day, great to see you here! If you'd like to follow my first suggestion for something to work on today, of adding property-based tests with Hypothesis, and you're new to the subject, you can start reading about it here: http://hypothesis.rtfd.io/
I can demo an example of adding a new property-based test for everyone on a screenshare at 10am Eastern. Join via https://meet.google.com/ouf-syai-xvv at that time if interested.
If you're interested in working on something else, let me know and I'll look forward to helping in any way I can!
Joshua Bronson
@jab
Also check out https://bidict.readthedocs.io/contributors-guide.html and let me know if you have any issues setting up a development environment.
Joshua Bronson
@jab
You may also wish to spend some time taking the "guided tour" through bidict's code that starts here: https://github.com/jab/bidict/blob/master/bidict/__init__.py (see the comment starting with "Welcome to the bidict source code" in the header)
Joshua Bronson
@jab
How's everyone doing?
Btw, someone please remind me to ask y'all if anyone wants to present at the Hack Day show-and-tell on Tuesday!
Neil Tiwari
@neiltiwari
@jab Some minor quick q:
  1. I noticed that https://github.com/jab/bidict/blob/07c2dcf1a75642af169da400bb40b59fe01fe3dd/tests/properties/test_properties.py#L354 is under test_properties but is it a property test?
  2. On https://github.com/jab/bidict/blob/07c2dcf1a75642af169da400bb40b59fe01fe3dd/tests/properties/test_properties.py#L267, is there a reason it is written that way with the pylint disable instead of assert hasattr(bi, "_isinv")