Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Eugene
    @Eugene-1984
    Does anybody knows anything about the import and\or import order side-effects for mypy? I have working code that mypy comlains abouth with Unexpected keyword argument error. And yet I am unable to reproduce it outside of a big project. I have a hierarchy of dataclassed and if it is all in a single file - mypy agrees and yet once its get distributed across several packages, error emerges.
    Marti Raudsepp
    @intgr
    @Eugene-1984 Have you tried deleting .mypy_cache? Has helped me on rare occasions.
    Eugene
    @Eugene-1984
    @intgr No, but this situation reproduces within CI so.. I'll try that regardless, thanks! Now I am trying make the whole project pass with mypy --strictand now metting lots of reexport errors. It is tiresome not to be able to imports to propagate implicitly via all to the top :(
    Eugene
    @Eugene-1984
    @intgr removing cache wont help, now I am thinking that the cyclic imports under TYPE_CHECKING hack may be the problem
    Massimo Redaelli
    @mredaelli
    Suppose I have a complicated Protocol for a callback. I would like to avoid typing all the parameters and return types in every callback definition. Is there a way to say something like @my_protocol def callback(a, b) and have mypy figure out the rest?
    Robot Wei
    @wyl8899

    Hi! In one of my projects, there's a specific dataclass I reuse a lot that's semantically an ordered an frozen dataclass, ediclass = partial(dataclass, order=True, frozen=True). I noticed this completely prevents mypy from treating it as a dataclass, which is 99% of mypy errors in this project.

    @Hellzed Have you found a solution? From the dataclass_makers constant you provided, I found its usage https://github.com/python/mypy/blob/ec76ccafa757c6d8fbb2c83195170bf75e0ff324/mypy/plugins/default.py#L92, which is get_class_decorator_hook(). IMO chances are a custom plugin providing get_class_decorator_hook() would work.

    Wojciech Niedźwiedź
    @Niedzwiedzw
    @Niedzwiedzw
    good day
    django.core.exceptions.ImproperlyConfigured: django-configurations settings importer wasn't correctly installed. Please use one of the starter functions to install it as mentioned in the docs: https://django-configurations.readthedocs.io/
    that's what happens when I'm running "mypy"
    [mypy]
    files=wwau,../../shared
    ignore_missing_imports=true
    plugins =
    mypy_django_plugin.main
    how do I even debug this? the app runs fine
    Wojciech Niedźwiedź
    @Niedzwiedzw
    trying to introduce mypy to my company's existing codebase, ehh
    Gniourf
    @Gniourf

    I'm having a weird behavior with dict's get method:

    from typing import Dict, Generic, Optional, TypeVar
    
    K = TypeVar("K")
    X = TypeVar("X")
    
    
    # def weird(k: K) -> Optional[X]:
    #     d: Dict[K, X]
    #     return d.get(k, None)
    
    
    class NS_gen(Generic[K, X]):
        def __init__(self, ns: Dict[K, X]) -> None:
            self._dict: Dict[K, X] = ns
    
        def get0(self, key: K) -> Optional[X]:
            return self._dict.get(key, None)

    As is, mypy throws the error: error: Argument 1 to "get" of "Mapping" has incompatible type "K" ; expected "Optional[X]"

    But if the function weird is uncommented, mypy's error disappears... I've tried to find something related to this error in github's issues, but I wasn't able to find something that looks related.

    Gniourf
    @Gniourf
    Ok, nvm, it's probably due to mypy's cache
    Philipp Hahn
    @pmhahn
    CONTRIBUTING.md talks about using pre-commit, but not on how to set it up: virtualenv -p /usr/bin/python3 .venv && .venv/bin/activate. Still it fails for me when it runs flake8 because of E704 Multiple statements on one line. Creating a tox.ini with [flake8] ignore = E704 fixed it for me. Did I miss something and/or why isn't this conf included somewhere in tox.ini, setup.cfg, pre-commit or wherever?
    Eugene
    @Eugene-1984
    Does mypy supports PEP 560 yet? I have error: "MyClass[T]" has no attribute "__orig_bases__" error while the code runs OK for __orig_bases__ exists as per PEP 560 that was accepted!
    Yang Bo
    @Bryant-Yang
    hi, is there any option for only show "Cannot find implementation or library stub", but not show "Skipping analyzing 'X'"?
    when ignore_missing_imports is False.
    Chris Norman
    @chrisnorman7
    Hi, I want to create a dictionary like {name: cls}, where name is of type str, and cls will be a subclass of google.protobuf.message.Message. How can I do this so that mypy will ensure cls will always inherit from google.protobuf.message.Message?
    Marti Raudsepp
    @intgr
    Type[Message]
    Chris Norman
    @chrisnorman7
    Great, thanks. That worked. I forgot the typing module had a Type class, in addition to the lower case builtin version.
    Tomasz Trębski
    @kornicameister

    hello guys,

    can someone tell if it is possible (in plugin) to create Expr ouf of Type, Something like we have builtins.int and want to create IntExpr?
    or maybe using different words and a little of context: how can I transform OpExpr into what this operation actually produces.
    something like: OpExpr [ 10 ^^ 2]? We have a pow that will create an IntExpr, right?
    how can I do something like that?

    Ref: kornicameister/loguru-mypy#49
    This might give a little bit more context.

    Tanner Stirrat
    @tstirrat15
    class BaseClass:
      _class_defined_by_derived_class: ClassVar[Type[ThatClassBaseType]]
      def get_new_instance(self):
        return self._class_defined_by_derived_class()
    
    class DerivedClass:
      _class_defined_by_derived_class = ASubclassOfThatClass
    Is there a way to type get_new_instance so that when I call DerivedClass().get_new_instance() it's correctly typed? setting aside the question of whether this class hierarchy makes sense.
    luk-f-a
    @luk-f-a
    hi, could someone help me with an easy question? why is the revealed type Any after a cast?
    import numpy as np
    from typing import cast, Union
    
    
    def foo(x: int) -> None:
        a:Union[np.ndarray]  = cast(np.ndarray, np.zeros(1))
        reveal_type(a) #  Revealed type is 'Any'
    Alexander Ivanov
    @alehander92
    please use python/typing
    channel
    luk-f-a
    @luk-f-a
    thanks!
    Iwan Aucamp
    @aucampia
    What is the best way to deal with windows specific things in ctypes? https://github.com/aucampia/pallets-click/blob/iwana-typing-000/src/click/_winconsole.py
    e.g. from ctypes import windll # type: ignore
    this whole file is only imported on windows
    so I need to somehow ignore it for linux
    okay I see
    Fabian Becker
    @halfdan
    I'm getting "Signature of 'transformer' incompatible with supertype 'GenericQuery'" for the following funcs:
    class GenericQuery:
        @staticmethod
        def transformer(_arguments: Dict[str, Any], result: Dict, **kwargs) -> Union[Dict, List[Dict]]: ...
    
    class Subtype(GenericQuery):
        @staticmethod
        def transformer(parameters: Dict[str, Any], result: Dict, **kwargs) -> Dict: ...
    Can a subtype not return a more specific response?
    Dict still meets the Union[Dict, List[Dict]] criteria..
    Iwan Aucamp
    @aucampia
    is there some way to use typing.Literal in python versions before 3.8?
    Thomas Grainger
    @graingert
    @aucampia yes, also the new channel is #python/typing
    Denis-Step
    @Denis-Step
    i have a bunch of problems using literals ; eg:
    error: Incompatible type for "trial_phases" of "Study" (got "Optional[Iterable[Union[Literal[0], Literal[1], Literal[2], Literal[3], Literal[4]]]]", expected "Union[Sequence[Union[float, int, str, Combinable, None]], Combinable, None]")
    2 replies
    EXPLOSION
    @A5rocks
    try in the new channel (#python/typing), but perhaps also include the code?
    Roy Williams
    @rowillia
    :wave: Hi all! Is there an API for getting type information for a given variable (referenced by line:column)? Context is I'm attempting to build a MyPyTypeProvider for LibCST (https://libcst.readthedocs.io/en/latest/_modules/libcst/metadata/type_inference_provider.html#TypeInferenceProvider) . https://mypy.readthedocs.io/en/stable/mypy_daemon.html#static-inference-of-annotations isn't quite what I want as that appears to only be at the function annotation level.
    1 reply
    Pyprohly
    @Pyprohly

    How can I can find redundant annotations in my codebase?

    a = 5
    b: int = a  # redundant annotation
    a + b

    Mypy has no --warn-redundant-annotations option.

    Jelle Zijlstra
    @JelleZijlstra
    I don't think there are tools for that
    Alexander Ivanov
    @alehander92
    usee python/typing not this channel
    Daniel Imberman
    @dimberman

    Hi everyone!

    I'm attempting to make a class that can house a series of decorators that can be imported from other packages. I'm running into an issue though, where I can't seem to get mypy to recognize the imported decorators

    class _TaskDecorator:
        def __init__(self):
            self.store = {"python": python_task, "virtualenv": _virtualenv_task}
            decorator = ProvidersManager().taskflow_decorators
            for decorator_name, decorator_class in decorator.items():
                self.store[decorator_name] = decorator_class
    
        def __getattr__(self, name):
            if self.store.get(name, None):
                return self.store[name]
            raise AirflowException("Decorator %s not found", name)
    
    
    task = _TaskDecorator()

    These added functions will work at runtime, but I can't get text completion or hinting to work in my IDE.

    I have attempted to create a stub file, which KIND OF works, but requires that I know the exact arguments to the methods beforehand (which is a problem as the packages can update without the main package updating). Is there anything I can do to make these @task.____ decorators show up in code completion?

    Daniel Imberman
    @dimberman
    Oh oops, sorry looksl ike this might be more of a python/typing question
    Laurent Kadian
    @lkadian
    Hi all, with mypy's 0.NNN versioning scheme, what will be the next version after 0.900?
    Jelle Zijlstra
    @JelleZijlstra
    the current version is 0.910
    next is expected to be 0.920
    Laurent Kadian
    @lkadian
    Sorry, I was asking for the next major release. It's at 0.9nn now. I.e. last major release went 0.812 -> 0.900, next major release 0.9nn -> ??
    Jelle Zijlstra
    @JelleZijlstra
    I see, I don't think we have an answer for that yet
    maybe we can go the html5lib route to 0.999999999 but I hope not
    mitch-mckenzie
    @mitch-mckenzie
    anyone using super-linter v4? Cannot seem to get it to puckup my .mypy.ini or mypy.ini in .github/linters trying to get it to honor this config. Works locally with the same version running in a 3.8 venv. https://github.com/github/super-linter/blob/master/dependencies/Pipfile.lock#L678 mypy.ini : [mypy]
    ignore_missing_imports = True