Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Kyle Altendorf
    @altendky
    @ignormies:matrix.org that's the idea, yeah, but this is checking separate stubs, not a program using the trio library. in fact, having that and running mypy against qtrio which uses trio is exactly what turned this up. i haven't figured out how to get that to be enforced against the combination of package and stubs.
    ignormies
    @ignormies:matrix.org
    [m]

    trio has a parameter defaulted to None and trio-stubs doesn't have that parameter hinted as Optional

    In this context, would the problem be in trio, or in trio-stubs?

    Kyle Altendorf
    @altendky
    @ignormies:matrix.org trio-stubs. it ought to have clock: typing.Optional[trio.abc.Clock] = ...,
    but just reporting the discrepancy would leave me a chance to pick which to change. so for the goal of catching this scenario, it doesn't matter which is wrong, i think.
    mahmoudajawad
    @mahmoudajawad:matrix.org
    [m]
    How can I trace a possible bug where class attribute with name defaults would lose its typing when used in inherited class? This only applies to an attribute with the name defaults.
    RK
    @sonthonaxrk

    Hey there, how can I dissable the mypyc compilation when using the mypy command line?

    I'm trying to do some debugging of the source code, and I don't need it compiled. I just want to step through the code.

    4 replies
    Never mind, figured it out
    Bryan Forbes
    @bryanforbes
    @hauntsaninja I noticed that X as X is only re-exported for stubs… what happens in regular modules?
    It’s not really clear in the mypy release note blog post
    Kyle Altendorf
    @altendky
    ignormies
    @ignormies:matrix.org
    [m]
    So is it just not possible?
    Kyle Altendorf
    @altendky
    @hauntsaninja should stubtest check the package and the stubs against each other when it comes to implicit optional hints? context is 9 messages up, but trio has a parameter =None and the stubs have : trio.abc.Clock = .... seems like it would be good to have some tool or another able to find this discrepancy.
    RK
    @sonthonaxrk
    Is anyone here familiar with writting plugins for mypy?
    I'm trying to dynamically add a method to ca ClassDef in a plugin hook.
    What I can't work out is: how to construct new Function definitions.
    Because those function definitions need types in their args.
    But I don't know how to get arbitrary types
    RK
    @sonthonaxrk
    I know this is a really dumb question, but how can I construct mypy.nodes.Var objects?
    And mypy.nodes.TypeInfo
    This message was deleted
    RK
    @sonthonaxrk
    Sorry for thinking outloud
    RK
    @sonthonaxrk
    I think lookup_fully_qualified is what I need.
    It'd be nice if there was autodocumentation for the plugin api
    6 replies
    Henry Schreiner
    @henryiii
    :heart: MyPy 0.800 :heart:
    RK
    @sonthonaxrk
    @freundTech thanks for your help. I've actually managed to do something pretty cool with it.
    Basically, I was getting really annoyed with how a lot of python web developers just do ad hoc interfaces between services. And I wanted to see if I could create a metaprogrammed OpenAPI client; but one where I could also use MyPy to verify you are using the API correctly.
    Shantanu
    @hauntsaninja
    @bryanforbes agreed that the blog post is a little confusingly worded. PEP 484 was amended to say that only import X as X counts as an explicit re-export, not import X as Y. What happens in regular .py files depends on whether or not you have --implicit-reexport or not
    Bryan Forbes
    @bryanforbes
    Thanks! If the import X as X is included in __all__ in a regular .py file, will it be exported?
    Shantanu
    @hauntsaninja
    yeah, symbols in __all__ should be exported
    @altendky stubtest does check that default values are a subtype of the arg's type hint
    maybe the issue is that your stub is decorated?
    Bryan Forbes
    @bryanforbes
    @hauntsaninja thanks!
    Kyle Altendorf
    @altendky
    @hauntsaninja the stub uses ... for the default. it seems like the package default isn't checked against the stub hint. or at least isn't enforcing no implicit optional
    Shantanu
    @hauntsaninja
    @altendky can you remove the decorator and try?
    Kyle Altendorf
    @altendky
    @hauntsaninja i tried removing it and it didn't seem to make a difference. it sounds like you expect it ought to be caught so i'll make up a minimal example to try to confirm expectations and outcome. thanks.
    Kyle Altendorf
    @altendky
    @hauntsaninja https://gist.github.com/altendky/3327ab219a04e27f628b92aa6c480d8a here's the minimal example. i can certainly file a ticket if you think it is appropriate.
    also, this isn't a pressing issue. at this point i'm starting to just merge the stubs into the package so this is relevant primarily in the context of just improving (i think? :]) stubtest.
    Shantanu
    @hauntsaninja
    @altendky if i change your repro to create a pyi file instead of a py file in package-stubs, i get:
    error: package.f is inconsistent, runtime argument "p" has a default value of type None, which is incompatible with stub argument type builtins.int
    Stub: at line 1
    def (p: builtins.int =)
    Runtime: at line 1 in file /Users/shantanu/tmp/lol/package/__init__.py
    def (p=None)
    altendky @altendky sighs
    Kyle Altendorf
    @altendky
    bad repro, sorry.
    i'll explore the difference between that and the actual situation. thanks.
    Shantanu
    @hauntsaninja
    thanks for making a repro though! :-) let me know if there's something i could add to stubtest to make debugging easier
    DW
    @DW07045298_twitter
    Hi, can anyone help me understand what is wrong with my annotations on my code https://bpa.st/MGSOM . mypy thinks there is an error on L8 but I dont understand what is wrong. It looks like mypy correctly restricts to one type of a Union when it enters an if block but it throws that knowledge away when it enters a locally defined function (compare L5 & L7). Is this a mypy bug?
    DW
    @DW07045298_twitter
    from typing import Union
    
    def foo(X: Union[int, str]) -> bool:
        if isinstance(X, str):
            reveal_type(X)  # str
            def g(y: int) -> bool:
                reveal_type(X)  # Union[int, str]
                return len(X) > y  # <<<<< error: Argument 1 to "len" has incompatible type "Union[int, str]"; expected "Sized"
    
            return g(10)
    
        reveal_type(X)  # int
        return bool(X)
    Jahnavi-Jonnalagadda
    @Jahnavi-Jonnalagadda
    Hi There! How can we use an if statement in a for loop statement?
    Anyone please
    Shantanu
    @hauntsaninja
    Alex Grönholm
    @agronholm
    @Jahnavi-Jonnalagadda please elaborate?
    Amndeep Singh Mann
    @Amndeep7
    Hi folks, like was stated in the documentation, I'm trying to manually go over the stub file created by stubgen so as to provide explicit types where possible instead of using Any. I'm currently running into a snag where I don't know how to deal with a NewType that I defined - what I'm trying to do results in a mypy error. Please find below a minimal reproduction of the problem. Does anyone have any advice or am I forced to leave it as Any?
    # test.py
    from dataclasses import dataclass
    from typing import NewType
    
    A = NewType("A", str)
    
    @dataclass
    class Test:
        a: A
    # stubgen'd test.pyi
    from typing import Any
    
    A: Any
    
    class Test:
        a: A
        def __init__(self, a: Any) -> None: ...
    # trying to remove 'Any' as much as possible
    from typing import Type
    
    A: Type[str]
    
    class Test:
        a: A # mypy error: "test.A" is not valid as a type
        def __init__(self, a: A) -> None: ... # mypy error: "test.A" is not valid as a type
    Johannes Bechberger
    @parttimenerd
    Has anyone experiences with supervising a thesis that has a student working on mypy? I'm going to supervise a bachelors thesis starting in April that is focused on analysing the exhaustiveness of structural pattern matching in mypy (https://pp.ipd.kit.edu/thesis.php?id=323&lang=en), as a colleague of mine developed such an analysis for Haskell.