Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bryan Forbes
    @bryanforbes
    if you import with *, it automatically exports those things imported
    rpgoldman
    @rpgoldman
    @bryanforbes Thanks! Not sure how I missed that.
    Bryan Forbes
    @bryanforbes
    it’s easy to miss
    rpgoldman
    @rpgoldman
    Another question: PyMC3 (probabilistic programming library) has objects for random variables. These random variables are normal RVs, but if you pass the constructor a size argument, they make arrays of identical RVs (more accurately, they create an object that represents an array of identical RVs), and become indexable. Is there a good way to capture this sort of thing that might be indexable in a stub?
    Ethan Smith
    @ethanhs
    @rpgoldman we are working on adding a way to type array shapes, but it is still in the planning stages
    rpgoldman
    @rpgoldman
    @ethanhs The odd thing here is that the random variable either is or is not indexable (I think that's the right term). I.e., if you pass size=None to the constructor, you get a singleton object; if you pass size=<int> or size=<tuple> you get an indexable object.
    I wasn't counting on being able to figure out if the shape is right, just make the distinction between indexable and non-indexable.
    Ivan Levkivskyi
    @ilevkivskyi
    This probably can be dane with an overload
    Ethan Smith
    @ethanhs
    Yes in that case I agree an overload would make sense
    rpgoldman
    @rpgoldman
    So it's possible to overload a constructor?
    Ethan Smith
    @ethanhs
    Yes it should be
    rpgoldman
    @rpgoldman
    I suppose it should have occurred to me that it would be...
    Still a little odd, isn't it, because we have a single __init__ (with multiple overloads) for a single class, and the __init__ doesn't return anything, so I still don't see how this would let mypy tell when indexing into the resulting object is and is not kosher.
    It's possible that this is just problematic -- it occurs to me it's almost isomorphic to the issue of numpy arrays which may or may not be indexable (they may be 0-dimensional).
    Christoph Frädrich
    @FChris

    Hey there, are there any per-requisites for stubgen to generate stubs of annotated .py -files? I have a file with a dataclass and I would like to generate stub files for it. But when I run stubgen address I only get an empty __init__.pyi file. This is the python module

    from typing import Optional
    
    class Address:
        street: str
        housenumber: int
        housenumber_postfix: Optional[str]

    Am I missing something?

    Ivan Levkivskyi
    @ilevkivskyi
    It may be a stubgen bug. We just received a similar report few days ago
    Christoph Frädrich
    @FChris
    Alright, thank you.
    rpgoldman
    @rpgoldman
    Sorry to bang on about this, but is there a way to declare a class that "might be indexable"?
    rpgoldman
    @rpgoldman
    Actually, maybe this isn't a problem. Looks like singletons are indexable as foo[0], so this class is always Indexable. Sorry about the noise.
    rpgoldman
    @rpgoldman
    I thought I could work this out, but I'm afraid not -- what is the right superclass for a class that supports numerical indexing, but for which one can't predict the precise form? One StackExchange poster suggests Dict[Tuple[int,...], T] for entry type T -- is that right?
    I.e., should I make that a superclass of my class hierarchy in the stubs, or should I define __getitem__ using that tuple type as the index type, on the superclass?
    rpgoldman
    @rpgoldman
    Is there a set of recommendations/examples about how to write stubs for the constructors of classes that invoke the super method? Do we need to collapse all of the arguments (*args, **kwargs) down to the leaves of the inheritance tree, or is there some way to tell mypy about this? Do we just put in the __super__ invocation?
    Nathaniel J. Smith
    @njsmith
    how difficult would it be to teach mypy to issue an error when it sees a call-returning-an-awaitable that doesn't have an await in front of it?
    I just spent a few minutes looking at what it would take to do this in pylint, and the only hard part seems to be that it's annoying to figure out which calls return awaitables when you don't have a real type inference engine
    Zsolt Dollenstein
    @zsol
    I know pyre is going to have this soon 😜
    Zsolt Dollenstein
    @zsol
    Sometimes there's a valid reason for not immediately awaiting the return value though. The easy case is when the await able is passed to something like asyncio.gather which accepts an await able. The tricky one is where you call the function but only await it later
    Nathaniel J. Smith
    @njsmith
    @zsol I'm the author of an alternative to asyncio where those cases never occur
    (and we just had another person mentioning in chat that forgetting await bit them, so it got me thinking about it again)
    Zsolt Dollenstein
    @zsol
    You can still do something like this in trio, can't you?
    async with open_nursery():
        coro = call_my_async_function()  # would be nice to suppress a type error here
        do_some_other_things
        await coro
    Nathaniel J. Smith
    @njsmith
    @zsol you can, but it's 100% useless, and being able to flag forgotten awaits is useful, so I'm perfectly happy to forbid it
    also the interpreter itself already discourages you from doing this – it prints a warning whenever you don't await a coro → you should never create a coro without being sure to await it → creating a coro before doing some stuff that might return/raise is a bad idea
    Zsolt Dollenstein
    @zsol
    that's fair. I guess the only practical scenario this ever came up for me is when I'm not sure if call_my_async_function is actually async or not; then I could inspect if coro is awaitable or not and await it appropriately.
    Nathaniel J. Smith
    @njsmith
    presumably in that case the type checker will not know whether call_my_async_function returns an awaitable either :-)
    Zsolt Dollenstein
    @zsol
    not really, it returns a Union. But I think we went on a tangent. I also think the type checker is the best place for this kind of warning :)
    Nathaniel J. Smith
    @njsmith
    right, so in this hypothetical type checking mode, we wouldn't error on an un-awaited Union
    Ivan Levkivskyi
    @ilevkivskyi
    I think we already have a feature request issue for this in mypy. It is actually should be easy to implement (but we have another few hundred things to implement, so it is hard to estimate unless someone will contribute).
    Ivan Levkivskyi
    @ilevkivskyi
    Here is the issue python/mypy#2499
    Ivan Levkivskyi
    @ilevkivskyi
    Announcement: mypy 0.630 was just released http://mypy-lang.blogspot.com/2018/09/mypy-0630-released.html
    Ethan Smith
    @ethanhs
    :tada: hooray!
    jhbuhrman
    @jhbuhrman
    Nice! :thumbsup:
    Bryan Forbes
    @bryanforbes
    @ilevkivskyi now that mypy 0.630 is out the door, do you think you’ll have time to look at my sqlalchemy-stubs PRs?
    Ivan Levkivskyi
    @ilevkivskyi
    Yes, sorry for letting you wait
    we had a couple of regressions in the release (PRs are up now).
    I think I will take a look at the PRs very soon
    Bryan Forbes
    @bryanforbes
    @ilevkivskyi great!
    Tomáš Mládek
    @tmladek
    Hi, why does mypy throw an error for the second case, but not the first? https://paste.pound-python.org/show/W4hnw0B2hr76tZC38Lrw/
    Ivan Levkivskyi
    @ilevkivskyi
    Because it doesn't check unannotated methods/functions
    see PEP 484
    Tomáš Mládek
    @tmladek
    @ilevkivskyi I see, thanks!
    Sergei Izmailov
    @sizmailov
    Hi, I have a virtual environment with installed package "foo". I am able to execute main.py which uses "foo" via python main.pywhile python -m mypy main.py gives me error: Cannot find module named 'foo'.
    Module "foo" is pure-python. This module is located at ./venv/lib/python3.5/site-packages/foo.