Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    why doesn't mypy take body of conditional statements as a different scope?
    if some_bool:
         this_var: TypeOfVar =  TypeOfVar()
        this_var: DifferenTypeOfVar = DifferenTypeOfVar()
    Omry Yadan
    Is there as config flag to make --strict the default?
    Brian Mboya
    is there a way I could potentially get rid of this error. Apparently mypy has a file called types and python thinks it's the same file and trying to get BuiltinFunctionType from it.
    Traceback (most recent call last):
      File "main.py", line 3, in <module>
        import argparse
      File "/usr/lib/python3.8/argparse.py", line 88, in <module>
        import re as _re
      File "/usr/lib/python3.8/re.py", line 124, in <module>
        import enum
      File "/usr/lib/python3.8/enum.py", line 2, in <module>
        from types import MappingProxyType, DynamicClassAttribute
      File "/home/kreebz/Projects/opensource/mypy/mypy/types.py", line 3, in <module>
        import copy
      File "/usr/lib/python3.8/copy.py", line 111, in <module>
        types.BuiltinFunctionType, type(Ellipsis), type(NotImplemented),
    AttributeError: partially initialized module 'types' has no attribute 'BuiltinFunctionType' (most likely due to a circular import)
    Hi ! I'm playing with mypy and I see some "starred" types, like X* (see https://gist.github.com/70d59f208548878654505b0b9c89f0a2 line 45 vs 54). What's the difference between X and X* ?
    oups, you moved :)
    Axel Mousset
    This message was deleted
    Hi! I'm trying to extract type infomation of python files. Is that possible to be done by mypy? I have found the api.py file of mypy, but can't find a deeper api that about type infomation. Thanks for any ideas!
    Alexander Ivanov
    Jason R. Coombs
    Am I the first person to try to install mypy on pypy? When I do, it fails with an installation error on typed_ast, which is closed without resolution.
    Jason R. Coombs
    Does the resolution there imply that mypy is perpetually not supported on pypy?
    I didn’t see anything in the readme about pypy. Would the project consider a PR that advertises that pypy isn’t supported?
    Alexander Ivanov
    please use
    this channel is not suported
    Jason R. Coombs
    Got it. Thanks. I did follow the link from the project, but because that opened in a browser, it wasn’t authenticated so I had to try to find the channel manually and found this with a search. I see the message above now also.
    Hi, is there a function to convert a Optional value to a non-Optional value?
    47: def unopt(x: Optional[X]) -> X:
    48:     # similar to https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap
    49:     assert x is not None
    50:     return x
    I came across this, is it part of a library?
    max w

    Hi folks! Had a quick mypy question.

    In my venv I have a third-party library, chalice, in my site-packages.
    The library has inline types. It does not have a py.typed file.
    However, when trying to consume it, mypy seems to think it does not have types

    A quick repro is attached as a thread:

    4 replies
    max w
    (update: yeah, i think i just needed to make chalice PEP 561 compatible)
    Alexander Ivanov
    use this channel only
    Implicit return in function which does not return for "NoReturn" hint
    Does anyone meet this situational?
    Is it a bug?
    Deepti Sharma
    Hi Everyone
    I ama begineer with BeautifulSoup library and I am using it to extract row and column data from a website. But in the code, I am getting "Undefined name row_td"
    I am stuck. Can anyone help?

    from typing import Any

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    import bs4

    from urllib.request import urlopen
    from bs4 import BeautifulSoup

    url = "https://mcs.ciena.com/InetReports/AssemblyHistory/ResultsByAO.asp?SN=NNTMRT112ND8&PN=NTK540BC-820&R=008"
    html = urlopen(url)
    soup = BeautifulSoup(html, 'lxml')
    title = soup.title

    text = soup.get_text()


    rows = soup.find_all('tr')
    for row in rows:
    row_td = row.find_all('td')
    str_cells = str(row_td)
    cleantext = BeautifulSoup(str_cells, "lxml").get_text()

    Its here:
    for row in rows:
    row_td = row.find_all('td')
    Hi all. Anybody know how to run mypy on a directory, but NOT inspect files in the folders above it? For example, I have a folder src that then contains two modules myapp.fonts. When I run mypy src/myapp/fonts it is inspecting every app in my django directory.
    Yang Bo
    Hi guys, how to make sub class method return value compatible with it's base class?
    error: Incompatible return value type (got "AbstractUnitOfWork", expected "SqlAlchemyUnitOfWork")
    Yang Bo
    class AbstractUnitOfWork(abc.ABC):
        def __enter__(self) -> AbstractUnitOfWork:
            return self
    class SqlAlchemyUnitOfWork(AbstractUnitOfWork):
        # True: when in pytest, don't persist db changes
        # False: when in pytest, persist db changes
        is_pytest_non_persistence = True
        def __init__(self, session: scoped_session) -> None:
            self._session = session
        def __enter__(self) -> SqlAlchemyUnitOfWork:
            return super().__enter__()
    Yang Bo

    ok, subclass of type annotation
    for class:

    def func(sub_cls: Type[Base]):

    for instance

    Uow  = TypeVar("Uow", bound=AbstractUnitOfWork)
    def func(instance: Uow):
    Loris Zinsou
    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.
    To my surprise, the decorators for dataclasses are actually hardcoded: https://github.com/python/mypy/blob/master/mypy/plugins/dataclasses.py#L19
    Any idea how I could register a custom dataclass_maker to mypy?
    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
    @Eugene-1984 Have you tried deleting .mypy_cache? Has helped me on rare occasions.
    @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 :(
    @intgr removing cache wont help, now I am thinking that the cyclic imports under TYPE_CHECKING hack may be the problem
    Massimo Redaelli
    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

    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.