Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
    Tushar Sadhwani
    @tusharsadhwani
    <reposting this here from python/typing>

    Hey,
    I've been trying to contribute to mypy since the past couple months. I understand that the maintainers don't owe the contributors anything, but I've been sitting on a PR for weeks on-end simple because I'm a first time contributor and github won't run its CI workflows until someone manually re-runs it.

    I've had to wait a week to get someone to notice, just to realise I missed a very small edge case. For me, I'm talking about python/mypy PR #10959 and a couple others, but I can imagine this happening to anyone trying to contribute. I'm not sure what the solution is, but I wanted to bring attention to this.

    Tory Clasen
    @tclasen
    Hello, I'm getting a billion of these errors, .venv/lib/python3.10/site-packages is in the MYPYPATH. Please remove it., how do I remove my virtual environment from the MYPYPATH?
    EXPLOSION
    @A5rocks
    The chat has moved to https://gitter.im/python/typing but I personally haven't had to set MYPYPATH and I doubt venvs are there by default (?)
    Sam Grayson
    @charmoniumQ
    Are tuples covariant in Mypy?
    Yohann Rebattu
    @yobuntu_gitlab
    Hello, i dont get why equality expression are not considered as boolean:
    return a == b => mypy complain about returning any instead of bool
    return True if a == b else False => mypy does not complain anymore (but it looks ugly)
    i can't find information about that (maybe i don't get the rights keywords
    Stephanos Kuma
    @spapanik_gitlab
    I have a typing issue, that the return type is controlled from a boolean
    Alexander Görtz
    @nylocx
    Hi, anyone an idea how it can be that mypy comlains about incompatible types in assignment even if the type is the same for variable and expression?
    Zaharid
    @Zaharid
    Hello, I would like to make a runtime validation library that is compatible with mypy annotations. If I annotate something with the output of the Parser function below, then both mypy and my library can work with that
    from typing import Annotated, Any
    import inspect
    
    
    __all__ = ["InputType", "Validator", "Parser"]
    
    
    class InputType:
        def __init__(self, type):
            self.type = type
    
        def __repr__(self):
            return f'{self.__class__.__name__}({repr(self.type)})'
    
    
    class Validator:
        def __init__(self, func):
            self.func = func
    
        def __call__(self, *args, **kwargs):
            return self.func(*args, **kwargs)
    
        def __repr__(self):
            return f'{self.__class__.__name__}({repr(self.func)})'
    
    
    def Parser(func):
        s = inspect.signature(func)
        if not s.parameters:
            raise ValueError("Expecting at least one parameter")
        ret = s.return_annotation
        if ret is s.empty:
            ret = Any
    
        p = next(iter(s.parameters.values()))
        inp = p.annotation
        if inp is s.empty:
            inp = Any
        return Annotated[ret, InputType(inp), Validator(func)]
    For example the commented line here
    def json_float(
        inp: Union[int, float, Literal["Infinity"], Literal["-Infinity"], Literal["NaN"]]
    ) -> float:
        return float(inp)
    
    JSONFloat = Parser(json_float)
    #JSONFloat = typing.Annotated[float, InputType(typing.Union[int, float, typing.Literal['Infinity'], typing.Literal['-Infinity'], typing.Literal['NaN']]), Validator(json_float)]
    The question is how do I get mypy to work with the uncommented line, that genetates the annotation dynamically?
    MaKaNu
    @MaKaNu
    Hello Together,
    I am relative new to python static typehinting. I use it a lot but never checked before with mypy. Sadly I started with a bit more complex scenario for testing: pyside6 and Slots. I understand that my Slot decorator expects types as arguments, but it seems that mypy has problem with optional arguments like Slot's result. How to set it up correctly?
    LUTAAYA HUZAIFAH IDRIS
    @huxaiphaer
    I have a path in a Django app I want to ignore or exclude, but it doesn't work, this is my path : accounts/management/commands, where accounts is a Django app, and this is what I have added in the mypy.ini, but no luck, whats the best approach :
    [mypy-*.management.commands.*]
    # Ignore all management commands directories.
    ignore_errors = True
    Brendan
    @2bndy5
    Is there a way to output mypy wanings/errors in a json format? I'd like to write a problem matcher for my github actions workflow.