Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ivan Levkivskyi
    @ilevkivskyi
    IMO this may be tricky to fix (although doesn't require new features), it is just a tricky/old part of mypy
    SaschaSchlemmer
    @SaschaSchlemmer
    any chance that there is a core dev that would really like to dig his/her teeth into this kind of issue? I know this is probably quite low priority since it is so obscure a usecase.
    Ivan Levkivskyi
    @ilevkivskyi
    It is actually high priority because it appears in really many such obscure cases. However most people are on vacations, so there is no chance this gets fixed before September (October is more realistic)
    SaschaSchlemmer
    @SaschaSchlemmer
    That's encouraging! I really like the direction mypy/python is moving and proper support for typed generics and higher order functions is a big one for being a functional-ish/ multiparadigm language
    Christopher Sabater Cordero
    @cs-cordero
    Hello, is this a bug?
    class Base(ABC):
        @property
        @abstractmethod
        def whatever(self) -> str:
            raise NotImplementedError
    
        @classmethod
        def custom_instantiator(cls: Type[T]) -> T:
            instance = cls()
            ...
            return instance
    
    class Sub(Base):
        pass
    
    Sub()  # error: Cannot instantiate abstract class 'Sub' with abstract attribute 'whatever'
    Sub.custom_instantiator()  # no error
    i would expect that there would be an error when using custom_instantiator.
    Joshua Oreman
    @oremanj
    @cs-cordero AIUI, mypy assumes that when you use the cls: Type[T] pattern, cls refers to something that can be instantiated, because that's a very common use case and it's not clear how such a constraint could be represented explicitly
    And mypy doesn't do interprocedural analysis, so it can't consider whether specifically calling Sub.custom_instantiator() is valid, only whether the definition of custom_instantiator() is valid in isolation
    Aritra Biswas
    @pandalearnstocode
    Hi. Can we use mypy with numba typed list ? Is it possible to use mypy for numpy data types?
    Ivan Levkivskyi
    @ilevkivskyi
    Currently numeric stack is not very well supported, there are some experimental type stubs in numpy-stubs project. You still can use mypy, but it is unlikely it will catch any bugs. We are going to work on adding a better support at some point soon.
    Michael Joseph Rosenthal
    @micimize
    So, I've made some progress on my dynamic class generation by hacking parse, but I'm at a loss as to how I should go about adding generated attributes to class_def.info https://github.com/micimize/datapackage-attrs/blob/master/datapackage_attrs/mypy_plugin.py
    Ivan Levkivskyi
    @ilevkivskyi
    You add them to the symbol table, you can look at mypy.plugins.common.add_method() for an example
    Michael Joseph Rosenthal
    @micimize
    @ilevkivskyi thanks - would I be able to add raw AssignmentStmts for attributes?
    Ivan Levkivskyi
    @ilevkivskyi
    No
    You need to add a Var
    Michael Joseph Rosenthal
    @micimize
    @ilevkivskyi thanks! I think I'm a lot closer now, but probably need to rework the original attrs plugin instead of constructing fake context
    Anvar Umarov
    @arpanetus
    @ilevkivskyi May I ask you a question?
    Ivan Levkivskyi
    @ilevkivskyi
    Yes, go ahead.
    Anvar Umarov
    @arpanetus
    if my python project is not pythonic in the structure, how to tell mypy that the importing file belongs to the project itself?
    image.png
    Ivan Levkivskyi
    @ilevkivskyi
    I am not sure what exactly you mean, you can just put list of files/directories when running mypy.
    If really needed you can use MYPYPATH
    Anvar Umarov
    @arpanetus
    currently i'm running mypy sicp_bot/db/manager.py with a mypy.ini file configured in the root directory of the project
    Ivan Levkivskyi
    @ilevkivskyi
    Anvar Umarov
    @arpanetus
    sorry for misreading :~) I've set the PYTHONPATH variable and everything works fine now
    rpgoldman
    @rpgoldman
    I have been making a typed subclass of UserDict, and getting an odd error. First, I use this as the header -- is this right:
    class _ExtendableTrace(UserDict, Dict[str, np.ndarray]):
    When I do that, I get errors from mypy as follows:
    posterior_predictive.py:135: error: Definition of "fromkeys" in base class "UserDict" is incompatible with definition in base class "dict"
    posterior_predictive.py:135: error: Definition of "copy" in base class "UserDict" is incompatible with definition in base class "dict"
    Ivan Levkivskyi
    @ilevkivskyi
    rpgoldman
    @rpgoldman
    @ilevkivskyi Thanks! Yes, that works!
    Louis Opter
    @lopter
    Hello, I am wondering why this is invalid:
    from typing import List
    
    class MyObject:
      List = List["MyObject"]
      my_attr = True
    
    my_list: MyObject.List = []  # mypy says MyObject.List is an invalid type.
    Joshua Oreman
    @oremanj
    You can't scope type aliases like that, unfortunately
    Louis Opter
    @lopter
    It would be so cool though?
    Joshua Oreman
    @oremanj
    The current reality is what it is independent of coolness
    Ivan Levkivskyi
    @ilevkivskyi
    FWIW this works on master
    what is the version you are using
    Joshua Oreman
    @oremanj
    Oh cool, was that a new-semanal feature?
    Louis Opter
    @lopter
    whatever is on pypi
    (fixed the link)
    ^^ @lopter
    Louis Opter
    @lopter
    Oh no, my laptop has an older version indeed
    Ivan Levkivskyi
    @ilevkivskyi
    @oremanj I think it was supported before to some extent
    Louis Opter
    @lopter
    That's awesome
    Gareth T
    @garetht
    is there a way during or after typechecking to iterate through an AST containing mypy's inferred types for every expression (as if reveal_type were placed in the appropriate places)?
    Ivan Levkivskyi
    @ilevkivskyi
    There is no easy way to do this (no public API)
    You can find an example of how to do this in mypyc compiler (that still lives in a separate repo for historical reasons)
    Gareth T
    @garetht
    thanks!
    Benjamin Kirkbride
    @Beefy-Swain
    Hey all
    Is there a list of big 3rd party projects that have strict type annotations? As in, no any types, all functions annotated, etc
    I was wanting to use flask for something, but found that it has a lot of any types
    catern
    @catern
    I have a bunch of mixins which I want to have all take different arguments in their init; is there a way to do this in a type-safe way? it looks like the normal Python way to do it would be with an opaque **kwargs that you just propagate through to super().init, which is not very type-safe